Instead of using ALTER TABLE ADD COLUMN create a new table with an extra column and copy the old data. This will free you from ALTER TABLE constraints and allow you to have a NOT NULL without a default value.
ALTER TABLE YourTable RENAME TO OldTable; CREATE TABLE YourTable (, NewColumn DATETIME NOT NULL); INSERT INTO YourTable SELECT *, '2000-01-01 00:00:00' FROM OldTable; DROP TABLE OldTable;
Edit: The official SQLite documentation for ALTER TABLE now warns against the above procedure, as it "may corrupt links to this table in triggers, views, and foreign key constraints." A safe alternative is to use a temporary name for the new table, for example:
CREATE TABLE NewTable (, NewColumn DATETIME NOT NULL); INSERT INTO NewTable SELECT *, '2000-01-01 00:00:00' FROM YourTable; DROP TABLE YourTable; ALTER TABLE NewTable RENAME TO YourTable;
dan04 Jun 12 2018-10-12T00: 00Z
source share