-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.

4
  • 3
    Its answered it for you. You are trying to apply a default of NULL to a column that says don't allow null. Commented Aug 17, 2017 at 8:19
  • 8
    "Cannot add a NOT NULL column with default value NULL" ... well, yes? What would you expect? Commented Aug 17, 2017 at 8:19
  • Answer in laracast website check this out laracasts.com/discuss/channels/general-discussion/… Commented Aug 17, 2017 at 8: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. Commented Aug 17, 2017 at 8:21

1 Answer 1

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?

Sign up to request clarification or add additional context in comments.

1 Comment

Yes, alter table "markers" add column "user_id" integer not null DEFAULT 0.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.