Reputation: 2326
public static final String Database_Name="content.db";
public static final int Database_Version=1;
public static final String Table_Name="images";
public static final String Column1="contentid";
public static final String Column2="content_type";
public static final String Column3="content";
public static final String Column4="has_update";
public static final String Column5="server";
public static final String Column6="_id";
public static final String Create_Database =
"CREATE TABLE " + Table_Name +
" (" + Column6 + " INTEGER PRIMARY KEY AUTOINCREMENT, " +
Column1 + " LONG, " +
Column2 + " TEXT NOT NULL, " +
Column3 + " TEXT NOT NULL, " +
Column4 + " INTEGER, " +
Column5 + " INTEGER); ";
i am creating a table in android database by using above code and executing Create_Database query but i am getting an error in logcat saying autoincrement can be assigned to only an integer primary key? what am i doing wrong here?
02-17 21:08:27.016: E/SQLiteLog(8460): (1) AUTOINCREMENT is only allowed on an INTEGER PRIMARY KEY
this is the error i am getting in logcat.Any help.....
Upvotes: 0
Views: 5480
Reputation: 5258
Try this
public static final String Create_Database =
"CREATE TABLE " + Table_Name +
" (" + Column6 + " INTEGER PRIMARY KEY, " +
Column1 + " LONG, " +
Column2 + " TEXT NOT NULL, " +
Column3 + " TEXT NOT NULL, " +
Column4 + " INTEGER, " +
Column5 + " INTEGER " + ")";
A column declared INTEGER PRIMARY KEY will autoincrement.
Upvotes: 5
Reputation: 6527
Try NOT NULL
to prevent second error.
Also try like this INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT
Upvotes: -1