Laravel MariaDB错误:150“外键约束错误形成”

时间:2017-01-13 17:06:25

标签: mysql laravel mariadb laravel-5.3

我的帖子迁移是:

includes(:photo, :video).where('photos.is_processing IS NULL').rank(:position_in_gallery)

和频道:

        Schema::create('posts', function (Blueprint $table) {
        $table->increments('id');
        $table->string('channel_id');
        $table->foreign('channel_id')->references('id')->on('channels');
        $table->string('title');
        $table->text('content');
        $table->string('status')->default('published');
        $table->string('type');
        $table->string('published_at');
        $table->timestamps();
    });

现在,当我执行 Schema::create('channels', function (Blueprint $table) { $table->increments('id'); $table->string('name'); $table->string('description'); $table->string('channel_id'); $table->timestamps(); }); 时,出现以下错误消息:

php artisan migrate

我正在使用Laravel 5.3,那就是我在我的本地计算机上使用MySQL就可以完美地运行迁移。但是当我在服务器上上传我的Laravel项目并在服务器上使用MariaDB时。我看到了错误信息。

1 个答案:

答案 0 :(得分:2)

posts表格迁移中更改此内容:

$table->string('channel_id');

对此:

$table->integer('channel_id')->unsigned();

另外,请确保在channels表迁移之前运行posts表迁移。