简体   繁体   English

Laravel 6-MariaDB 10.1:Illuminate \\ Database \\ QueryException:SQLSTATE [HY000]迁移错误

[英]Laravel 6 - MariaDB 10.1: Illuminate\Database\QueryException : SQLSTATE[HY000] migration error

I have custom migration: 我有自定义迁移:

Code: 码:

// Groups migration
Schema::create('groups', function (Blueprint $table) {
    $table->bigIncrements('id');
    $table->string('name');
    $table->boolean('status')->default(false);
    $table->timestamps();
});

// Clients migration
Schema::create('clients', function (Blueprint $table) {
    $table->bigIncrements('id');
    $table->string('fullname');
    $table->integer('phone');
    $table->date('birthday')->nullable();
    $table->boolean('can_get_congratulations')->default(false);
    $table->unsignedInteger('group_id')->default(null);
    $table->foreign('group_id')
          ->references('id')
          ->on('groups')
          ->onDelete('cascade');
    $table->boolean('status')->default(true);
    $table->timestamps();
});

When I run this migration file then get error message: 当我运行此迁移文件时,出现错误消息:

Illuminate\\Database\\QueryException : SQLSTATE[HY000]: General error: 1005 Can't create table taxisms . Illuminate \\ Database \\ QueryException:SQLSTATE [HY000]:常规错误:1005无法创建表taxisms #sql-1cc0_65c (errno: 150 "Foreign key constraint is incorrectly formed") (SQL: alter table clients add constraint clients_group_id_foreign foreign key ( group_id ) references groups ( id ) on delete cascade) #sql-1cc0_65c (错误号:150“外键约束#sql-1cc0_65c不正确”)(SQL:更改表clients添加约束, clients_group_id_foreign外键( group_id )引用删除级联上的groupsid ))

在此处输入图片说明

Where I have an error in my migration code? 迁移代码中哪里有错误?

The column needs to match on both sides. 该列需要在两侧都匹配。 Since groups.id is an unsigned big integer, group_id will need to be as well. 由于groups.id是一个无符号的大整数,因此group_id也必须是。 Change 更改

$table->unsignedInteger('group_id') 

to

$table->unsignedBigInteger('group_id')

See this Blog Site. 请参阅此博客网站。 I hope that this article helpful to you. 希望本文对您有所帮助。 Also, know another topic on this site. 另外,请知道此站点上的另一个主题。

https://eduproblem.xyz/ https://eduproblem.xyz/

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Docker Laravel 迁移错误 Illuminate\Database\QueryException SQLSTATE[HY000] - Docker Laravel migration error Illuminate\Database\QueryException SQLSTATE[HY000] Laravel 6 - Mysql - Docker - Illuminate\Database\QueryException SQLSTATE[HY000]:一般错误:2036 - Laravel 6 - Mysql - Docker - Illuminate\Database\QueryException SQLSTATE[HY000]: General error: 2036 Illuminate\Database\QueryException:SQLSTATE[HY000]:一般错误:1813 Tablespace for table - Illuminate\Database\QueryException : SQLSTATE[HY000]: General error: 1813 Tablespace for table php artisan migrate - 错误 - Illuminate\Database\QueryException: SQLSTATE[HY000] [2054] - php artisan migrate - Error - Illuminate\Database\QueryException : SQLSTATE[HY000] [2054] Illuminate\Database\QueryException: SQLSTATE[HY000]: General error: 1 no such table - 在克隆项目中 - Illuminate\Database\QueryException: SQLSTATE[HY000]: General error: 1 no such table - In clone project Illuminate\Database\QueryException: SQLSTATE[HY000] [2002] 在文件 Illuminate/Database/Connection.php 上的第 678 行 - Illuminate\Database\QueryException: SQLSTATE[HY000] [2002] in file Illuminate/Database/Connection.php on line 678 Illuminate \\ Database \\ QueryException (2002) SQLSTATE[HY000] [2002] 没有这样的文件或目录 (SQL: select * from `rents`) - Illuminate \ Database \ QueryException (2002) SQLSTATE[HY000] [2002] No such file or directory (SQL: select * from `rents`) php artisan migrate Illuminate\\Database\\QueryException SQLSTATE[HY000] [2054] 上的异常 - Exception on php artisan migrate Illuminate\Database\QueryException SQLSTATE[HY000] [2054] 如何修复“Illuminate\\Database\\QueryException: SQLSTATE[HY000] [1044] Access denied for user” - How to fix “Illuminate\Database\QueryException: SQLSTATE[HY000] [1044] Access denied for user” Illuminate\Database\QueryException: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (使用密码: YES) - Illuminate\Database\QueryException : SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM