I am trying to create an SQLite database from within a C# WinForms application. I am using the System.Data.SQLite
library as found on sqlite.org
I can create the database fine, and I can create tables fine too. The problem comes when I need to add a new column where I don't want to allow nulls, but I don't want to specify a default value either.
For creating a table I would use a query such as this:
CREATE TABLE MyTable (ID INTEGER PRIMARY KEY AUTOINCREMENT)
The problem occurs when I then run this query:
ALTER TABLE MyTable ADD COLUMN Col1 nvarchar NOT NULL
This is producing the following error:
SQL logic error or missing database Cannot add a NOT NULL column with default value NULL
I understand why this might be a problem if the tables contained data, but all the tables are empty (they have only just been created).
I am also able to manually add the NOT NULL columns without defaults to the database using a separate tool (SQLiteStudio).
So why am I not able to do this? Is there something wrong with my query?