1
假設我有一個表periods
,列start_date
和end_date
,我想添加一個約束start_date < end_date
。如何使用Laravel的遷移將約束添加到表中?
PostgreSQL的查詢將是:
ALTER TABLE periods ADD CONSTRAINT check_dates CHECK ("start_date" < "end_date");
但我想這樣做與PHP遷移。我想它會看起來像這樣:
Schema::table('periods', function (Blueprint $table) { $table->something(); });
...但即使智能感知,我無法猜測要寫什麼而不是「something()」。
我沒有使用最新版本的Laravel,因此如果您從代碼的哪個版本添加代碼,並且您可以在舊版本中執行哪些操作,那將會很不錯。