【发布时间】:2021-05-22 14:23:04
【问题描述】:
我正在尝试使用 foreignId 从另一个表中获取 ID,但它不会让我这样做。
我的用户表:
public function up()
{
Schema::create('users', function (Blueprint $table) {
$table->id('user_id');
$table->string('first_name', 40);
$table->string('last_name', 40);
$table->string('email')->unique();
$table->timestamp('email_verified_at')->nullable();
$table->string('password');
$table->foreignId('tier_id')->references('tier_id')->on('tiers');
$table->rememberToken();
$table->timestamps();
});
}
我的层表:
public function up()
{
Schema::create('tiers', function (Blueprint $table) {
$table->id('tier_id');
$table->string('name');
$table->float('price');
$table->string('max_resolution');
$table->integer('max_users');
$table->timestamps();
});
}
我做错了什么,请帮忙!
已解决,方法如下: Espresso 的评论似乎有帮助,迁移完美完成,我需要做的就是更改文件名。谢谢!
【问题讨论】:
-
只要把你的
tires迁移文件的名字改成2014_10_11_000000_create_tiers_table.php,问题就解决了 -
Espresso 的评论有帮助,我尝试了其他人,但他们没有用。谢谢!
-
哦,抱歉,我是 SOF 的新手,谢谢!