Php Laravel迁移-列已存在
我正在运行Laravel Framework 5.2.45版,希望迁移我的数据库迁移 我有两次迁移。一个是现成的标准Php Laravel迁移-列已存在,php,laravel,laravel-5,laravel-5.2,Php,Laravel,Laravel 5,Laravel 5.2,我正在运行Laravel Framework 5.2.45版,希望迁移我的数据库迁移 我有两次迁移。一个是现成的标准2014\u 10\u 12\u 100000\u创建\u密码\u重置\u表,另一个是我新创建的迁移2017\u 02\u 19\u 172350\u创建\u关键字\u表: <?php use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Migrations\Migration; class
2014\u 10\u 12\u 100000\u创建\u密码\u重置\u表
,另一个是我新创建的迁移2017\u 02\u 19\u 172350\u创建\u关键字\u表
:
<?php
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateKeywordsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('keywords', function (Blueprint $table) {
$table->increments('id');
$table->string('keyword');
$table->timestamps();
$table->timestamps('published_at');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('keywords');
}
}
在数据库中,没有创建表关键字
有什么建议我做错了什么
谢谢你的回复 $table->timestamps()
是一个函数,它总是在处添加创建的字段和在
处添加更新的字段。在您的情况下,将添加两次。
如果要添加另一个时间戳字段,必须使用timestamp()
函数
因此,您应该将位于
的published_的行替换为以下内容(删除s):
可以在中找到所有可能列类型的列表。尝试composer dump命令,然后尝试php aristan迁移:刷新
root:~/workspace $ php artisan migrate:rollback
Rolled back: 2014_10_12_100000_create_password_resets_table
root:~/workspace $ php artisan migrate
[Illuminate\Database\QueryException]
SQLSTATE[42S21]: Column already exists: 1060 Duplicate column name 'created_at' (SQL: create table `keywords` (`id` int unsigned not null auto_incr
ement primary key, `keyword` varchar(255) not null, `created_at` timestamp null, `updated_at` timestamp null, `created_at` timestamp null, `updated
_at` timestamp null) default character set utf8 collate utf8_unicode_ci)
[PDOException]
SQLSTATE[42S21]: Column already exists: 1060 Duplicate column name 'created_at'
root:~/workspace $
$table->timestamp('published_at');