Laravel 8
由于某些原因,我的暂存环境不允许我运行迁移。
我得到以下错误。
General error: 1215 Cannot add foreign key constraint (
SQL: create table `login_credentials` (
`id` char(36) not null,
`username` varchar(75) not null,
`confirmation_code` varchar(36) null,
`deleted_at` timestamp null,
`remember_token` varchar(100) null,
`created_at` timestamp null,
`updated_at` timestamp null)
default character set utf8mb4
collate 'utf8mb4_unicode_ci'
engine = InnoDB)我还没有定义任何外键,这似乎是最近才开始的。我为我的应用程序编写了单元测试,所以我的大部分开发都是在本地完成的。
在推进生产之前,我很少会上传到暂存服务器来进一步测试更详细的内容。如果这是一个小的可协商的改变,那么一旦单元测试通过并验证一个干净的构建,它就会从本地到生产。因此,不幸的是,从现在到几周前,这成了一个问题。
我的login_credentials迁移文件。
class CreateLoginCredentialsTable extends Migration
{
public function up(): void
{
Schema::create('login_credentials', function (Blueprint $table) {
$table->uuid('id')->nullable(false)->unique()->primary();
$table->string('username',75)->unique();
$table->string('confirmation_code',36)->nullable()->unique();
$table->softDeletes();
$table->rememberToken();
$table->timestamps();
});
}
}我在Stackoverflow上到处搜索,并尝试了以下几种方法。
migration
H 219H 219H 120将laravel迁移文件移动到我的迁移文件夹中,并将Cashier::ignoreMigrations(); Passport::ignoreMigrations();添加到我的appserviceprovider中,并更新这些迁移文件,以确保user_id不是bigInt,或Int,并将其定义为uuid。
。
在本地主机上运行迁移文件运行良好,没有错误。
有什么想法吗?
甚至删除了除单个login_credentials表之外的所有迁移文件,但仍然得到相同的错误?我要疯了吗?

发布于 2021-10-29 03:12:14
我的分阶段数据库和生产数据库都在同一个mysql服务器上。
来了解一下,您可以从一个具有相似或相同表的不同数据库中获得一个外键约束,并在您正在处理的数据库中提出这些问题。
回答这个问题,而不是在罕见的情况下删除它,另一个人会像面包屑一样穿越这个区域。
“无法添加外键约束”检查其他数据库的约束
https://stackoverflow.com/questions/69762311
复制相似问题