-3

I'm testing a laravel site using codeception and I've followed the following tute:

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

I'm getting the following error:

[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)

Thanks in advance.

M. Eriksson
  • 13,450
  • 4
  • 29
  • 40
Jerome Papalie
  • 21
  • 2
  • 10
  • 3
    Its answered it for you. You are trying to apply a default of NULL to a column that says don't allow null. – rbaskam Aug 17 '17 at 08:19
  • 8
    *"Cannot add a NOT NULL column with default value NULL"* ... well, yes? What would you expect? – CD001 Aug 17 '17 at 08:19
  • Answer in laracast website check this out https://laracasts.com/discuss/channels/general-discussion/migrations-sqlite-general-error-1-cannot-add-a-not-null-column-with-default-value-null – lotfio Aug 17 '17 at 08:20
  • It's weird though, because even if the default value is NULL, you could still specify a value, which in that scenario would be mandatory. Nevertheless, this is a limitation of the specific underlying database, and not really a PHP problem. If you think the ORM/Database framework of Laravel is the issue, or the way you use it, please share at least the code that causes this error. – GolezTrol Aug 17 '17 at 08:21

1 Answers1

4

Your real problem is called ALTER TABLE. If you want to add NOT NULL column, you need to set DEFAULT for existing records! Otherwise, what can the database do?

Thinkeye
  • 888
  • 12
  • 22