Unable to add NOT NULL field without default value
Issue #277
resolved
Comments (6)
-
-
- marked as minor
-
- marked as enhancement
-
(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.)
-
repo owner - changed status to resolved
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>>
-
Just solved this issue by using the ALTER TABLE workaround in this case. Of course it only works if the table is empty. You can get the newest development version here: https://phpliteadmin.christosoft.de/phpliteadmin.zip
Please confirm if this fixes your problem.
- Log in to comment
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