2016-04-23 116 views
0

我使用Laravel 5.2并希望更改默认用户表的列。我在CreateUsersTableLaravel默认用户表

public function up() 
    { 
    Schema::create('users', function (Blueprint $table) { 
     $table->increments('id'); 
     $table->string('name'); 
     $table->string('email')->unique(); 
     $table->string('password'); 
     $table->rememberToken(); 
     $table->timestamps(); 
    }); 

    Schema::table('users', function ($table) { 
     $table->string('role'); 
     $table->string('info'); 
     $table->string('age'); 
     $table->string('hobies'); 
     $table->string('job'); 
    }); 
    } 

写道 和我在GIT的bash运行这些命令,但用户表没有改变。

php artisan migrate:refresh 
    php artisan migrate 

我该如何解决它?

回答

0

运行php artisan migrate命令后,您应该运行composer dumpauto -o注册新的迁移,以便它们可以回滚。

试试吧。如果它不会工作,尝试删除所有表,包括migrations并运行此命令:

php artisan migrate:install 
+0

谢谢你,但我发现解决这个问题的简单方法。 – Earthx9

0

你只需要改变一下它的内部Schema::create和删除您Schema::table

然后,你需要实现参观down() mehod并添加Schema::drop('users');以便在运行migrate:refresh时放下您的桌子。

您可以阅读laravel文档中的'数据库迁移'以获取更多详细信息。

+0

谢谢,但我已经做到了,但没有奏效。 – Earthx9

0

创建新的迁移文件,做这样的事情

public function up() { 
    DB::statement('ALTER TABLE user ADD some_field INT');// your query here 
} 

php artisan migrate