Laravel5 database table Creation

Source: Internet
Author: User
I followed @ JellyBool's video learning. Run the following command on the CMD command line. {Code ...} then, the following code {code...} is written in 2015_10_23_022143_create_articles_table.php ...} then run the command on CMD and an error is displayed, and the database does not display the error... I followed @ JellyBool's video learning.
Run the following command on the CMD command line.

php artisan make:migration create_articles_table --create=articles

Then, the following code is written in 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 the command on CMD and an error is displayed, which is not displayed in the database.articlesTable, where is the field already exists?

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_increme  nt primary key, `title` varchar(255) not null, `content` text not null, `cr  eated_at` timestamp default 0 not null, `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 already exists: 1060 Duplicate column name 'created  _at'

Reply content:

I followed @ JellyBool's video learning.
Run the following command on the CMD command line.

php artisan make:migration create_articles_table --create=articles

Then, the following code is written in 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 the command on CMD and an error is displayed, which is not displayed in the database.articlesTable, where is the field already exists?

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_increme  nt primary key, `title` varchar(255) not null, `content` text not null, `cr  eated_at` timestamp default 0 not null, `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 already exists: 1060 Duplicate column name 'created  _at'

Okay, I finally found out that it was my negligence.

$ Table-> timestamps ('hhed _ at'); change to $ table-> timestamp ('published _ ');

Timestamps () is different from timestamp. The former is a Laravel method used to manage creation and modification as the created_at and updated_at TIMESTAMP columns. This is the same as the method below, which leads to repeated fields.

Run the php artisan migrate command.
It fails. How can you execute it successfully?
[PDOException]
SQLSTATE [HY000] [1045] Access denied for user 'root' @ 'localhost' (using pas
Sword: YES)

The version 5.1. evn file I used is modified as follows:
DB_HOST = 127.0.0.1
DB_DATABASE = homestead
DB_USERNAME = root
DB_PASSWORD = secret
An error is returned when the above sentence is executed.

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.