php - Laravel 8 - 用户表中的两个外键
问题描述
我想创建两个人可以创建会议室的应用程序。但我不知道如何在 Laravel 中制作模式。
我试图这样创建:
Schema::create('appointments_tables', function (Blueprint $table) {
$table->id();
$table->unsignedBigInteger('user_id');
$table->unsignedBigInteger('user_id2');
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
$table->foreign('user_id2')->references('id')->on('users')->onDelete('cascade');
$table->datetime('start');
});
}
这是正确的方法吗?
解决方案
是的,这是正确的。
您还可以使用工匠命令“php artisan make:migration”。
以下是该命令帮助标志的详细信息:
$ php artisan -help 制作:迁移
描述:
创建一个新的迁移文件
用法:
make:migration [选项] [--]
论据:
name 迁移的名称
选项:
--create[=CREATE] The table to be created
--table[=TABLE] The table to migrate
--path[=PATH] The location where the migration file should be created
--realpath Indicate any provided migration file paths are pre-resolved absolute paths
--fullpath Output the full path of the migration
-h, --help 显示此帮助消息 -q, --quiet 不输出任何消息 -V, --version 显示此应用程序版本 --ansi 强制 ANSI 输出 --no-ansi 禁用 ANSI 输出 -n, -- no-interaction 不要问任何交互式问题 --env[=ENV] 命令应该运行的环境 -v|vv|vvv, --verbose 增加消息的详细程度:1 表示正常输出,2 表示更详细的输出和3 用于调试
推荐阅读
- javascript - NestJS 中的 DI 是如何工作的?
- mysql - MySQL 错误:无法更新存储函数/触发器中的表“用户”,因为它已被调用此存储函数/触发器的语句使用
- r - Factor() 通过表中获得的统计相关性对 ggplot2 中的方面进行排序
- bash - 无法使用 az cli 列出订阅中所有资源组的资源
- python - 如何从 Django 模型下载图像或文件
- android - Android 11 - 访问私有存储中的文件
- javascript - 如何裁剪图像以适应屏幕尺寸而不是在网页中调整其大小?
- laravel - 数据表,加入同一张表?
- google-cloud-platform - 在 google cloud shell 上的 google storage 中解压 zip 文件
- python - ImportError: No module named libvirt error 为什么试图在 NetBSD 9.2 上为 libvirt 安装 python