android.database.sqlite.SQLiteException:table MyMovies没有名为_ReleaseDate的列

时间:2013-02-19 21:51:59

标签: android database sqlite android-sqlite

我的数据库中有这个表

  public static final String TABLE_MOVIES_NAME = "MyMovies";
  public static final String TABLE_MOVIES_COLUMN_ID = "_Id";
  public static final String TABLE_MOVIES_COLUMN_NAME = "_Name";
  public static final String TABLE_MOVIES_COLUMN_DATE_ADDED = "_AddedDate";
  public static final String TABLE_MOVIES_COLUMN_DATE_RELEASE = "_ReleaseDate";
  public static final String TABLE_MOVIES_COLUMN_DESCRIPTION = "_Description";

  private static final String DATABASE_NAME = "????.db";
  private static final int DATABASE_VERSION = 1;

  public static final String DATABASE_CREATE = "create table "
      + TABLE_MOVIES_NAME + "("
      + TABLE_MOVIES_COLUMN_DATE_RELEASE + "text not null, "
      + TABLE_MOVIES_COLUMN_ID + " integer primary key, "
      + TABLE_MOVIES_COLUMN_NAME + " text not null, "
      + TABLE_MOVIES_COLUMN_DATE_ADDED + " text not null, "
      + TABLE_MOVIES_COLUMN_DESCRIPTION + " text not null);";

我尝试将一些值(电影)添加到其中ContentValues values = _ReleaseDate=2013-06-18 _Id=0 _Name=a _AddedDate=2013-02-18 _Description=asfsgagafgadf

当我插入database.insertOrThrow(SQLiteHelper.TABLE_MOVIES_NAME, null, values);
我收到此错误android.database.sqlite.SQLiteException: table MyMovies has no column named _ReleaseDate (code 1): , while compiling: INSERT INTO MyMovies(_ReleaseDate,_Id,_Name,_AddedDate,_Description) VALUES (?,?,?,?,?) 我做错了什么?

2 个答案:

答案 0 :(得分:2)

变化:

public static final String DATABASE_CREATE = "create table "
      + TABLE_MOVIES_NAME + "("
      + TABLE_MOVIES_COLUMN_DATE_RELEASE + "text not null, "
      + TABLE_MOVIES_COLUMN_ID + " integer primary key, "
      + TABLE_MOVIES_COLUMN_NAME + " text not null, "
      + TABLE_MOVIES_COLUMN_DATE_ADDED + " text not null, "
      + TABLE_MOVIES_COLUMN_DESCRIPTION + " text not null);";

为:

public static final String DATABASE_CREATE = "create table "
      + TABLE_MOVIES_NAME + "("
      + TABLE_MOVIES_COLUMN_DATE_RELEASE + " text not null, "//Space added here.
      + TABLE_MOVIES_COLUMN_ID + " integer primary key, "
      + TABLE_MOVIES_COLUMN_NAME + " text not null, "
      + TABLE_MOVIES_COLUMN_DATE_ADDED + " text not null, "
      + TABLE_MOVIES_COLUMN_DESCRIPTION + " text not null);";

答案 1 :(得分:0)

在此处添加空格:

  + TABLE_MOVIES_COLUMN_DATE_RELEASE + " text not null, "  // space before 'text'