Pramod Yadav
Pramod Yadav

Reputation: 2326

primary key autoincrement not working on android database?

  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

Answers (3)

user3079764
user3079764

Reputation: 1

try this

INTEGER PRIMARY KEY AUTOINCREMENT NULL

it works for me

Upvotes: -1

moDev
moDev

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

hakki
hakki

Reputation: 6527

Try NOT NULL to prevent second error.

Also try like this INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT

Upvotes: -1

Related Questions