第二个表迁移时发生Laravel 5.2数据库迁移错误

时间:2016-10-12 09:44:29

标签: laravel migration artisan

我使用的是Laravel 5.2。我确实使用php artisan make:migration create_users_table命令创建了迁移文件。文件创建成功,我用这段代码更新了文件:

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateUsersTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('users', function (Blueprint $table) {
            $table->increments('id');
            $table->integer('partner_id');
            $table->string('social_id');
            $table->integer('device_id');
            $table->integer('gcm_id');
            $table->integer('user_role');
            $table->string('social_media');
            $table->string('display_name');
            $table->string('first_name');
            $table->string('last_name');
            $table->integer('status');
            $table->string('email')->unique();
            $table->string('password');
            $table->string('profile_pic');
            $table->string('gender');
            $table->float('height');
            $table->float('weight');
            $table->string('dob');
            $table->bigInteger('mobile');
            $table->string('city');
            $table->string('state');
            $table->integer('zip');
            $table->string('country');
            $table->float('latitude');
            $table->float('longitude');
            $table->float('gps_status');
            $table->string('favorite_movie');
            $table->string('favorite_food');
            $table->string('favorite_weather');
            $table->integer('login_status');
            $table->string('active');
            $table->string('token');
            $table->rememberToken();
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::drop('users');
    }
}`

用于运行迁移我使用这个'php artisan migrate'命令。并发生错误

'迁移表已成功创建。

  

[Illuminate \ Database \ QueryException] SQLSTATE [HY000]:常规   错误:将'。\ laravel \ users'重命名为1025时出错   '。\ laravel#sql2-1d88-70'(错误:190 - 操作时不允许操作   innodb_forced_recov ery> 0)(SQL:alter table users添加唯一   users_email_uniqueemail))

     

[PDOException] SQLSTATE [HY000]:常规错误:1025错误   将'。\ laravel \ users'重命名为'。\ laravel#sql2-1d88-70'(错误号:190 -   innodb_forced_recov ery>时不允许操作0)'

之后我使用了rollback命令php artisan migrate:rollback但是消息没有显示回滚的内容,当我想创建第二个表时,消息显示the user table already exist

1 个答案:

答案 0 :(得分:0)

我认为回滚的问题在于,由于迁移尚未正确完成,因此尚未触发在db表中添加迁移的过程(作为最后一步),因此artisan命令无法将其还原。为了解决这个问题,我建议你手动从数据库中删除表。

问题在于迁移本身,在我的脑海中,我不记得Laravel的全新安装是否已经附带用户表,首先检查一下。如果确实如此,则需要更改表而不是创建它。如果没有,我可以看到迁移失败的任何明显原因。

相关问题