We want this operation to work when it can and fail when it has to. In some cases the user will specify NOT NULL and in others they won't. Of course we can drop and recreate the table but then we have to examine the request to see if the field has the NOT NULL constraint and then test to see if there is data in the table. It's not terribly difficult but it leads to a more complicated set of code paths than just giving it a shot and relying on SQLite to handle it correctly.
> Igor Tandetnik itandetnik at mvps.org <mailto:sqlite-users%40sqlite.org?Subject=%5Bsqlite%5D%20Adding%20a%20NO T%20NULL%20column%20fails%20on%20empty%20table&In-Reply-To=> > Mon Mar 16 18:23:40 GMT 2009 > Can't you just drop the table and create a new one? As the table is > empty, you won't be losing any data. > Igor Tandetnik From: Alex Ousherovitch Sent: Monday, March 16, 2009 11:13 AM To: 'sqlite-users@sqlite.org' Subject: Adding a NOT NULL column fails on empty table Hello list, The attempts to add a NOT NULL column on an empty table ALTER TABLE tbl_name ADD COLUMN col_name blob NOT NULL fail with the following error message: Cannot add a NOT NULL column with default value NULL As I understand, many other systems allow it when the table has no records. Is it a bug or a feature in SQLite? Thank you, Alex _______________________________________________ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users