Tag Archives: [O] SQLite

[How to Solve] SQLite database error: no such column

Add columns in the SQLite database creation statement, and an error is reported after running: no such column

On the premise of grammatical norms, i.e

//SQLite database creation, comma and space must be strict
String CREATE_NOTE = "create table "
			+ NotepadEntity.TABLE_NOTE
			+ " (" + NotepadEntity.NOTE_ID + " integer primary key autoincrement,"
			+ NotepadEntity.NOTE_TITLE + " varchar not null," //此列为修改语句后增加
			+ NotepadEntity.NOTE_CONTENT + " text not null,"
			+ NotepadEntity.NOTE_CREATE_DATE + " text);";

SQLiteDatabase db;
db.execSQL(CREATE_NOTE);

It still fails to compile because the SQLite create command has been executed once, and the database file already exists. Even if the statement is changed, it is not executed again

Solution:

Open the DDMS tool and locate the file   Explorer “, navigate to the database file list in the project file (expand to/data/data/& lt; package name>/ databases)

 

(you can export the database file to the computer, and use SQLite database browser and other tools to check whether there are columns of data not created)

Delete the database file and its journal file, return to the project and run again. If the program detects that the database is empty, execute the create command and compile

At this time, export the database file under DDMS, view the list structure, create the new column successfully, and solve the problem