php - 外键 Laravel 8 的迁移表
问题描述
添加外键并执行 php artisan migrate 时我遇到了问题:fresh
有错误
("SQLSTATE[42S21]: Column already exists: 1060 Duplicate column name 'id_rso'")
这是我的迁移表:
public function up()
{
Schema::enableForeignKeyConstraints();
Schema::create('dso', function (Blueprint $table) {
$table->string('id_dso',30);
$table->unsignedBigInteger('id_rso');
$table->foreignId('id_rso')->constrained('rso');
$table->smallInteger('id_focus');
$table->smallInteger('id_wilayah');
$table->smallInteger('id_grup_wilayah');
$table->string('nama_dso',50);
$table->string('created_by',50)->nullable();
$table->timestamp('created_date',$precision = 0);
$table->string('modified_by',50)->nullable();
$table->timestamp('modified_date',$precision = 0)->nullable()->default(null);
$table->boolean('status')->default(true);
$table->timestamps();
$table->primary('id_dso');
});
}
我正在将 mysql 用于数据库和 laravel 8
解决方案
$table->unsignedBigInteger('id_rso');
$table->foreignId('id_rso')->constrained('rso');
而不是这个,只需写:
$table->foreignId('id_rso')->constrained('rso');
推荐阅读
- sql - 连接查询SQL问题重复行主键?
- java - 如何使用地图和撰写模拟 Flowable?
- ios - 如何在不打开邮件编写器 iOS swift 的情况下发送电子邮件?
- pug - 如何在 PUG 3 模板中设置跨块变量?
- python - 为什么线性回归模型无法准确显示目标和预测的可视化?
- node.js - 点击功能上的角度隐藏div
- linux - 尽管存在文件,但在 Alpine Container 中找不到文件
- reactjs - Reactjs表应用按钮onclick不在页面中返回数据
- javascript - JavaScript 在按钮单击时显示/隐藏 div - 每页多个
- sql - 使用来自“with”语句的数组