我扩展了默认迁移,以为我的用户表包括一些其他表字段。
我想有created_at
和updated_at
字段timestamps
作为值。
这是我的代码
<?php
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateUsersTable extends Migration {
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('users', function(Blueprint $table)
{
$table->bigIncrements('id');
$table->bigInteger('group_id');
$table->string('fname',255);
$table->string('lname',255);
$table->string('email',255)->unique();
$table->string('password', 60);
$table->boolean('active');
$table->string('gravtar',255)->nullable();
$table->rememberToken();
$table->timestamps('created_at');
$table->timestamps('updated_at');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('users');
}
}
障碍是使用两个时间戳列不会迁移表并引发此异常
[PDOException]
SQLSTATE[42S21]: Column already exists: 1060 Duplicate column name 'created_at'
瞧,我只有一列有name created_at
,所以这种例外没有道理。但是,当我删除时间戳字段之一时,表将被迁移。
我不知道是什么原因造成的?
timestamps()方法同时添加created_at和updated_at列。同样,此方法不接受任何参数。
http://laravel.com/api/5.0/Illuminate/Database/Schema/Blueprint.html#method_timestamps http://laravel.com/docs/5.0/schema
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句