這是我的代碼Schema::create('employees', function (Blueprint $table) { $table->id(); $table->string('first_name'); $table->text('second_name'); $table->string('emp_company')->unsigned(); $table->string('email'); $table->string('phone'); $table->timestamps(); $table->foreign('emp_company')->references('company_name')->on('companies'); });這是我的錯誤:SQLSTATE[42000]: 語法錯誤或訪問沖突: 1064 您的 SQL 語法有錯誤;檢查與您的 MariaDB 服務器版本相對應的手冊,了解在第 1 行“unsigned not null, emailvarchar(255) not null, varchar(255) not null,”附近使用的正確語法(SQL: create table ( bigint unsigned not null auto_increment 主鍵、varchar(255) not null、text not null、varchar(255) unsigned not null、varchar(255) not null、varchar(255) not null、timestamp null、timestamp null) 默認字符集 utf8mb4 collate 'utf8mb4_unicode_ci ')phoneemployeesidfirst_namesecond_nameemp_companyemailphonecreated_atupdated_at我堅持這個..尋找支持謝謝。
1 回答

三國紛爭
TA貢獻1804條經驗 獲得超7個贊
我認為你的問題在這一行:
$table->string('emp_company')->unsigned();
unsigned 僅用于數字列,強制只使用正數,字符串列沒有 UNSIGNED,沒有意義
只需刪除 ->unsigned() 并且您的代碼應該可以工作......
- 1 回答
- 0 關注
- 140 瀏覽
添加回答
舉報
0/150
提交
取消