简体   繁体   English

如何在另一个表中使用数据类型字符串作为外键制作无主键

[英]How to make a no primary key with datatype sting as foreign key in another table

I am trying to make a non primary key as foreign key in another table whose datatype is string.I'm trying to reference doctor_id from users table 我试图在另一个数据类型为字符串的表中将非主键作为外键。我试图从用户表中引用doctor_id

Referenced Table 参考表

在此处输入图片说明

Referencing Table 参考表

在此处输入图片说明

you have to use unique modifier on your column. 您必须在列上使用unique修饰符。

$table->string('doctor_id')->unique();

however, if you set nullable as the modifier like: 但是,如果将nullable设置为修饰符,例如:

$table->string('doctor_id')->unique()->nullable();

it will present another problem when it has multiple records with the same value of null . 当它有多个具有相同null值的记录时,它将提出另一个问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM