我跟著@JellyBool的視頻學習。
在CMD命令列上運行了下面的命令。
php artisan make:migration create_articles_table --create=articles
然後在 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(); }); }
接著在CMD上運行就彈出錯誤了,資料庫裡也沒有顯示articles
表,是哪個地方出現了欄位重複?
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'
回複內容:
我跟著@JellyBool的視頻學習。
在CMD命令列上運行了下面的命令。
php artisan make:migration create_articles_table --create=articles
然後在 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(); }); }
接著在CMD上運行就彈出錯誤了,資料庫裡也沒有顯示articles
表,是哪個地方出現了欄位重複?
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'
好吧 終於發現了 是我的疏忽大意
$table->timestamps('published_at');應該改為$table->timestamp('published_at');
timestamps()與timestamp()不同。前者是一個 Laravel 用來管理建立和修改作為created_at和updated_at TIMESTAMP列的方法。所以跟下面的方法重複了,導致出現欄位重複的問題
樓主,我執行php artisan migrate
的時候就失敗,你怎麼可以執行成功
[PDOException]
SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using pas
sword: YES)
我用的5.1版本.evn檔案修改如下:
DB_HOST=127.0.0.1
DB_DATABASE=homestead
DB_USERNAME=root
DB_PASSWORD=secret
執行上面呢句就報錯