我跟着@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'
最后解决方法是:
删除所有表,再次执行php artisan migrate
不过我在操作过程中又出现了新的问题
>php artisan migrate [Illuminate\Database\QueryException] SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 1000 bytes (SQL: alter table `users` add uniqu e `users_email_unique`(`email`))
于是,我清空数据表,修改App/Providers/AppServiceProvider.php文件,
添加两行代码,use Illuminate\Support\Facades\Schema;和Schema::defaultStringLength(191);改变字段长度
<?php namespace App\Providers; use Illuminate\Support\ServiceProvider; use Illuminate\Support\Facades\Schema;//添加 class AppServiceProvider extends ServiceProvider { /** * Bootstrap any application services. * * @return void */ public function boot() { Schema::defaultStringLength(191);//添加 } /** * Register any application services. * * @return void */ public function register() { // } }