我有两个表,如User和Roles。我想在Table Users上添加外部Roles_id。
public function up()
{
Schema::create('users', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('NIK',16);
$table->string('nama');
$table->string('email')->unique();
$table->string('username');
$table->string('password');
$table->unsignedBigInteger('roles_id')->default(1);
$table->timestamps();
$table->softDeletes();
$table->foreign('roles_id')->references('id')->on('roles');
});
}
和我的角色表
public function up()
{
Schema::create('roles', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('roles');
$table->timestamps();
});
}
我没有捕获未命中的代码,我使用 unsignedBigInteger ,仍然出错。 我正在使用->可为空。但是没有工作。可以找到这个错误吗?
编辑。此错误:
SQLSTATE [HY000]:常规错误:1215无法添加外键约束(SQL:更改表
users
添加约束users_roles_id_foreign
外键(roles_id
)引用roles
(id
)
答案 0 :(得分:0)
首先,创建角色表:
for i in range(3,len(df1)):
#str(df1['VARIABLE'][i].contains('^\d'))
if (df1['VARIABLE'][i].astype(str).contains('^\d') == True):
然后创建一个用户表:
txtSearchFor = textbox
lstresult = listbox
Seng Piseth, [30.05.19 10:57]
Option Compare Database
Public Function kh(ByVal st As String) As String
Dim x As String
Dim i As Integer
For i = 1 To Len(st)
x = x & AscW(Mid(st, i, 1))
Next
kh = x
End Function
Private Sub txtSearchFor_KeyUp(KeyCode As Integer, Shift As Integer)
Dim rs As New ADODB.Recordset
Dim cnn As New ADODB.Connection
With rs
.CursorLocation = adUseClient
.CursorType = adOpenStatic
.LockType = adLockReadOnly
.Open "SELECT * FROM tbentryletter WHERE kh(let_name) LIKE '%" & kh(Me.txtSearchFor.Text) & "%'", cnn
Set Me.lstresult.Recordset = rs
.Close
End With
End Sub
用于放置外键:
public function up(){
Schema::create('roles', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('roles');
$table->timestamps();
});
}