【发布时间】:2016-04-18 07:34:57
【问题描述】:
我正在尝试使用 Sentinel 和 Laravel 5 注册一个人。`
Route::get('/', function () {
$credentials = [
'email' => 'john.doe@example.com',
'password' => 'password',
'client_id' =>1,
];
$user = Sentinel::register($credentials);
});`
我收到了这个回复
SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a
child row: a foreign key constraint fails (`dbmenubook`.`users`, CONSTRAINT
`fk_users_me_clients1` FOREIGN
KEY (`client_id`) REFERENCES `me_clients` (`id`) ON DELETE NO ACTION
ON UPDATE NO ACTION) (SQL: insert into `users`
(`email`, `password`, `updated_at`, `created_at`) values (john.doe@example.com,
y2016-02-23
16:02:31fQMyg1raDBf/dNrQGQMe.LDxEHO5yQCA.J5cbZKmyuLKLYzzUIra,
2016-02-23
16:02:31, ?))
现在我正在尝试添加给我这个错误的 client_id。但似乎 client_id 没有被发送。我猜它与模型和可填充数组有关,但这似乎没问题
用户模型
<?php
namespace App;
use Illuminate\Foundation\Auth\User as Authenticatable;
class User extends Authenticatable
{
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $table = 'users';
protected $fillable = [
'name', 'email', 'password',
];
/**
* The attributes excluded from the model's JSON form.
*
* @var array
*/
protected $hidden = [
'password', 'remember_token',
];
}
用户表
CREATE TABLE `users` (
`id` int(10) unsigned NOT NULL,
`email` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`password` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`permissions` text COLLATE utf8_unicode_ci,
`first_name` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
`last_name` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
`created_at` timestamp NULL DEFAULT NULL,
`updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`client_id` int(10) unsigned NOT NULL,
`last_login` timestamp NULL DEFAULT NULL,
`ipad_id` int(10) DEFAULT NULL
) ENGINE=InnoDB AUTO_INCREMENT=79 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
有谁知道问题出在哪里?
【问题讨论】: