外键上的Laravel迁移错误

时间:2015-09-04 01:16:00

标签: mysql laravel

我正在尝试创建此迁移:

public function up()
{
    // Create the `Dashboards` table
    Schema::create('dashboards', function(Blueprint $table)
    {
        $table->engine = 'InnoDB';
        $table->increments('id');
        $table->string('name');
        $table->tinyInteger('is_public');
        $table->timestamps();
    });

    // Creates the user_dashboard (Many-to-Many relation) table
    Schema::create('user_dashboard', function(Blueprint $table)
    {
        $table->engine = 'InnoDB';
        $table->increments('id');
        $table->integer('user_id')->unsigned();
        $table->integer('dashboard_id')->unsigned();
        $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
        $table->foreign('dashboard_id')->references('id')->on('dashboards')->onDelete('cascade');
    }); 
}

当我运行迁移时,我收到此错误:

SQLSTATE[HY000]: General error: 1005 Can't create table 
'prestiti_protestatinet.#sql-358f_9e6a9' (errno: 150) (SQL: alter table
`dl_user_dashboard` add constraint user_dashboard_user_id_foreign foreign 
key (`user_id`) references `dl_users` (`id`) on delete cascade)

这适用于我的本地环境(wampserver),但不适用于生产(灯泡)。这里有什么问题?

我的用户迁移:

    Schema::create('users', function(Blueprint $table)
    {
        $table->increments('id');
        $table->string('name');
        $table->string('email')->unique();
        $table->string('password', 60);
        $table->boolean('active')->default(0);
        $table->string('confirmation_code')->nullable();
        $table->rememberToken();
        $table->string('avatar')->nullable();
        $table->string('provider')->nullable();
        $table->string('provider_token')->unique()->nullable();
        $table->timestamps();
    });

0 个答案:

没有答案