Laravel5 database Table Establishment problem

Source: Internet
Author: User
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.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.