I am adding check constraint in sqlite android using create table query but Getting error like this
android.database.sqlite.SQLiteException: no such column: bloodgrp (code 1): ,
String query = " CREATE TABLE " register " ( "
Name " varchar(200), "
Age " TEXT, "
gender "TEXT, "
Email " TEXT, "
Username " TEXT, " "type UNIQUE, "
password " TEXT, "
contactNo "TEXT, "
Address "TEXT, "
city "TEXT, "
img "Blob ,"
bloodgrp " TEXT, "
Uid "TEXT, "
" CHECK " "(" bloodgrp ='A ''A-''B ''B-''AB ''AB-''O-''O " "))";
db.execSQL(query);
CodePudding user response:
Please use the check constraint as shown below. This answer assumes register, Name, Age, gender, Email, Username, password, contactNo, Address, city, img, bloodgrp, Uid are initialized correctly.
CHECK ( column_name in (value1, value2, value3))
String query = " CREATE TABLE " register " ( "
Name " varchar(200), "
Age " TEXT, "
gender "TEXT, "
Email " TEXT, "
Username " TEXT, " "type UNIQUE, "
password " TEXT, "
contactNo "TEXT, "
Address "TEXT, "
city "TEXT, "
img "Blob ,"
bloodgrp " TEXT, "
Uid "TEXT, "
" CHECK (" bloodgrp " in ('A ','A-','B ','B-','AB ','AB-','O-','O ')));";