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.articles
Table, 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.articles
Table, 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.