I followed @jellybool's video to learn.
The following command is run on the cmd command line.
PHP Artisan make:migration create_articles_table--create=articles
And then write the following code in the 2015_10_23_022143_create_articles_table.php.
Public function up () { schema::create (' articles ', function (Blueprint $table) { $table->increments (' Id '); $table->string (' title '); $table->text (' content '); $table->timestamps (' published_at '); $table->timestamps (); }); }
Then run on the cmd to pop the error, the database is not displayed articles
, where the field is duplicated?
d:\laravel>php Artisan Migrate [illuminate\database\queryexception] SQLSTATE[42S21]: Column already exists:1060 Duplicate column name ' Created _at ' (sql:create table ' articles ' (' id ' int unsigned NOT NULL Auto_increm E NT primary key, ' title ' varchar (255) Not NULL, ' content ' text is not NULL, ' CR eated_at ' timestamp default 0 not Nu ll, ' updated_at ' timestamp default 0 no t null, ' CREATED_AT ' timestamp default 0 NOT NULL, ' Updated_at ' timestamp d
efault 0 NOT NULL) default character set UTF8 collate utf8_unicode_ci) [pdoexception] SQLSTATE[42S21]: Column A Lready exists:1060 Duplicate column name ' Created _at '
Reply content:
I followed @jellybool's video to learn.
The following command is run on the cmd command line.
PHP Artisan make:migration create_articles_table--create=articles
And then write the following code in the 2015_10_23_022143_create_articles_table.php.
Public function up () { schema::create (' articles ', function (Blueprint $table) { $table->increments (' Id '); $table->string (' title '); $table->text (' content '); $table->timestamps (' published_at '); $table->timestamps (); }); }
Then run on the cmd to pop the error, the database is not displayed articles
, where the field is duplicated?
d:\laravel>php Artisan Migrate [illuminate\database\queryexception] SQLSTATE[42S21]: Column already exists:1060 Duplicate column name ' Created _at ' (sql:create table ' articles ' (' id ' int unsigned NOT NULL Auto_increm E NT primary key, ' title ' varchar (255) Not NULL, ' content ' text is not NULL, ' CR eated_at ' timestamp default 0 not Nu ll, ' updated_at ' timestamp default 0 no t null, ' CREATED_AT ' timestamp default 0 NOT NULL, ' Updated_at ' timestamp d
efault 0 NOT NULL) default character set UTF8 collate utf8_unicode_ci) [pdoexception] SQLSTATE[42S21]: Column A Lready exists:1060 Duplicate column name ' Created _at '
Well, finally, it's my carelessness.
$table->timestamps (' published_at '); should be changed to $table->timestamp (' published_at ');
Timestamps () differs from timestamp (). The former is a Laravel used to manage the creation and modification of methods as Created_at and updated_at timestamp columns. So the following method is repeated, causing the problem of field duplication
Landlord, I execute PHP artisan migrate
When you fail, how can you execute success
[Pdoexception]
SQLSTATE[HY000] [1045] Access denied for user ' root ' @ ' localhost ' (using pas
Sword:yes)
The 5.1 version of the. evn file that I used is modified as follows:
db_host=127.0.0.1
Db_database=homestead
Db_username=root
Db_password=secret
Execute the above sentence on the error.