2017-08-17 43 views
-4

我使用codeception測試laravel網站,我已經按照以下土特:無法添加具有默認值NULL的NOT NULL列

http://www.phplab.info/categories/laravel/how-to-specify-a-separate-database-for-unit-testing-on-laravel-5

,我發現了以下錯誤:

[Illuminate\Database\QueryException] SQLSTATE[HY000]: General error: 1 Cannot add a NOT NULL column with default value NULL (SQL: alter table "markers" add column "user_id" integer not null)

在此先感謝。

+3

它爲您解答。您正嘗試將NULL的默認值應用於不允許爲空的列。 – rbaskam

+8

*「不能添加具有默認值NULL的NOT NULL列」* ...嗯,是嗎?你會期待什麼? – CD001

+0

在laracast網站的答案檢查了這一點https://laracasts.com/discuss/channels/general-discussion/migrations-sqlite-general-error-1-cannot-add-a-not-null-column-with-default- value-null –

回答

1

你真正的問題叫做ALTER TABLE。如果您想添加NOT NULL列,則需要爲現有記錄設置DEFAULT!否則,數據庫可以做什麼?