laravel-6.2 - 一般错误:1005 无法创建表`learning`.`users`
问题描述
迁移我的数据库时出现此错误,下面是我的代码,后面是我在尝试运行迁移时遇到的错误
public function up()
{
Schema::create('users', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('name');
$table->string('email')->unique();
$table->timestamp('email_verified_at')->nullable();
$table->string('password');
$table->rememberToken();
$table->timestamps();
$table->string('first_name')->nullable();
$table->string('last_name')->nullable();
$table->string('city')->nullable();
$table->unsignedBigInteger('role_id');
$table->foreign('role_id')->references('id')->on('roles')->onDelete('cascade');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('users');
}
解决方案
错误 1005 与外键有关。确保您已经有角色表,否则它将在php artisan migrate上创建用户表 之前运行,只需通过编辑文件名将角色迁移文件放在用户之前。
2019_12_07_000000_create_roles_table.php
2019_12_08_000000_create_users_table.php
推荐阅读
- google-api - 需要 Google Drive api 权限值字段
- node.js - Agora.io:在云录制中获取 POST 调用 REST API 时遇到问题
- python - 如何使用 Snakemake 中的扩展功能对列表进行排列或组合
- php - Laravel 7 / SQL不区分大小写的where子句
- laravel - Laravel Algolia Scout, whereIn 关于关系
- react-native - react native iOS build failed on code push by: Undefined symbols for architecture x86_64:
- floating-point - double 类型的 IEEE 754 符合 sqrt() 实现
- c# - 与起订量作斗争 - 在被测方法中使用起订量
- sql - 在两列上连接表仅将其连接到一个
- css - 为轮播标题加载动画 CSS