Jaz*_*zzy 6 php mysql uuid primary-key laravel
我正在设置我的第一个Laravel 4应用程序,规范要求id字段为varchar(36)并且是UUID.
使用Eloquent,我对示例表的迁移如下所示:
Schema::create('users', function($table)
{
$table->string('id', 36)->primary;
$table->string('first_name', 50);
$table->string('last_name', 50);
$table->string('email')->unique();
$table->string('password', 60);
$table->timestamps();
$table->softDeletes();
});
Run Code Online (Sandbox Code Playgroud)
创建users表时,id字段未定义为PK或唯一.它被定义为varchar(36)NOT NULL.
为什么在我运行迁移时会发生这种情况?
我最初的问题是关于使用UUID,但我有意识地通过将此添加到我的Users模型解决了以防其他人看到此帖子:
protected $hidden = array('password');
protected $fillable = array('id', 'first_name', 'last_name', 'email', 'password');
Run Code Online (Sandbox Code Playgroud)
这是我添加用户的路径(我使用的函数来创建UUID):
Route::post('signup', function()
{
$userdata = array(
'id' => gen_uuid(),
'first_name' => Input::get('first_name'),
'last_name' => Input::get('last_name'),
'email' => Input::get('email'),
'password' => Hash::make(Input::get('password'))
);
$user = new User($userdata);
$user->save();
return View::make('login/login')->with('userdata', $userdata);
});
Run Code Online (Sandbox Code Playgroud)
这条线
$table->string('id', 36)->primary;
Run Code Online (Sandbox Code Playgroud)
必须改为
$table->string('id', 36)->primary();
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
5362 次 |
最近记录: |