一般錯誤:laravel 遷移 php 中的 1215

海拉德

這是我的錯誤:

General error: 1215 Cannot add foreign key constraint (SQL: alter table `author_book` add constraint `author_book_author_id_foreign` foreign key (`author_id`) references `author` (`id`))

我有表格書籍和帶有數據透視表的作者:

        Schema::create('books', function (Blueprint $table) {
        $table->increments('id');
        $table->unsignedInteger('user_id');
        $table->string('name');
        $table->unsignedInteger('pages');
        $table->string('ISBN');
        $table->integer('price');
        $table->date('published_at');

        $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade')->onUpdate('cascade');

作者表:

    public function up()
{
    Schema::create('authors', function (Blueprint $table) {
        $table->increments('id');
        $table->string('author');
        $table->date('birthdate');
        $table->timestamps();
    });
}

和我的數據透視表:

            $table->increments('id');

        $table->unsignedInteger('author_id');
        $table->unsignedInteger('book_id');

        $table->foreign('author_id')->references('id')->on('author');
        $table->foreign('book_id')->references('id')->on('books');
        $table->timestamps();

請幫我找出錯誤!

杰羅傑夫

你拼錯了作者表格。忘記了s

$table->foreign('author_id')->references('id')->on('authors');
//                                                        ^

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

一般错误:1215无法在Laravel中添加外键约束

如何在一次遷移中運行遷移文件夾

Laravel迁移的外键导致一般错误1215

postgresql 中的 Flyway 遷移?

Laravel 遷移拋出“SQLSTATE[HY000] [2002] php_network_getaddresses”異常

在 Laravel 遷移中,->nullable($value = true) 中的參數是什麼?

一般错误 1215:无法添加外键约束

在 Laravel 遷移中設置默認空數組

尝试在同一个表中创建外键时出现一般错误 1215,整数到整数

Laravel 8 一般错误:1215 无法添加外键约束

一般错误:1215 无法添加外键约束 - laravel 迁移

一般错误:1215无法添加外键约束,Laravel 5和MySQL

Laravel 8:无法创建外键 - “一般错误:1215 无法添加外键约束”

Laravel 8 迁移“一般错误:1215 无法添加外键约束”

Laravel迁移-一般错误:1215无法添加外键约束

檢查是否在遷移中

Django 多用戶類型遷移錯誤

Laravel 遷移,其中 id 列未命名為“id”導致錯誤

Laravel 8 外鍵遷移表

EFCore 運行單一遷移

PHP中的MVC –一般理解和特定问题

PHP Laravel PDOException一般错误引用列和外键约束中的引用列不兼容

Laravel 6 关于迁移:SQLSTATE[HY000]:一般错误:1215 无法添加外键约束

在遷移中定義或修改模型的正確方法

Yii2迁移一般错误:1215无法添加外键约束

PDOException::("SQLSTATE[HY000]: 一般错误:1215 无法添加外键约束")

用戶 REFERENCE 列的 PostgreSQL 遷移語法錯誤

Django 遷移:如何解決 charfield 到 datetimefield 的錯誤

如何修復 .NET 5.0 到 6.0 遷移錯誤