0

I have a table in my db like this :

. . .

 String contactsTableName = TABLE_CONTACTS;

            // creating the "contacts" table
            buf.append("CREATE TABLE IF NOT EXISTS ");
            buf.append(contactsTableName);
            buf.append(" (");
            buf.append("_id INTEGER PRIMARY KEY,");
            buf.append("username TEXT,");
            buf.append("nickname TEXT,");

            buf.append("provider INTEGER,");
            buf.append("account INTEGER,");
            buf.append("contactList INTEGER,");
            buf.append("type INTEGER,");
            buf.append("subscriptionStatus INTEGER,");
            buf.append("subscriptionType INTEGER,");
. . .  

And now i want to change this table and make username column UNIQUE, I wrote the onUpgrade() method i don’t know how is sql syntax for this purpose.
I change this code like this in my onCreate() :

buf.append("username TEXT UNIQUE");

I hope i explain my problem clear and apologise for my poor English. :)

YFeizi
  • 1,498
  • 3
  • 28
  • 50
  • seems ok as `username TEXT unique` will run. did you see any error. Also first empty all the data and remove the line `username TEXT` wrote earlier – Riad Aug 17 '16 at 05:25
  • Its not my app first release and i dont want users lost their data! its ok for new user but for users upgrade their app its a problem – YFeizi Aug 17 '16 at 05:29
  • i asked about the error you see. is there any? put the error logs. changing the column as unique may cause issue if any duplicate value is already there. – Riad Aug 17 '16 at 05:37
  • The problem is im not sure how can i write an alter statment for changing column – YFeizi Aug 17 '16 at 05:41
  • you are changing type which seems ok. so go with it and if any error occurs let us know – Riad Aug 17 '16 at 05:42

0 Answers0