Unable to add NOT NULL field without default value

Issue #277 resolved
Former user created an issue

bug_1.PNG

bug_2.PNG

Comments (6)

  1. Christopher Kramer

    This is a constraint of SQLITE, not phpLiteAdmin. "If a NOT NULL constraint is specified, then the column must have a default value other than NULL." [1]

    And this makes very much sense. You are adding a column to a table. In this table, there might already be some rows. When the column is added, what should the value be in these rows? It must not be NULL, because you specified it NOT NULL, but you also did not specify a default value, so what value should it be? SQLite does not know and therefore rejects the query.

    Of course we could say in the special case that the table is empty, we provide a workaround. I have to think about this.

    [1] http://sqlite.org/lang_altertable.html

  2. Christopher Kramer

    (This is not a bug of phpliteadmin. PhpLiteAdmin is a GUI for SQLIte and this a restriction of SQLite. We might provide a workaround, but not every missing SQLite feature is a bug of phpLiteAdmin.)

  3. phpLiteAdmin repo owner

    It is now possible to add a column with NOT NULL constraint without a DEFAULT value if the table is empty using our ALTER TABLE workaround. This fixes issue #277.

    → <<cset 896e36b0b66f>>

  4. Log in to comment