今天我已经开始应对数据库。我已经安装了SQLite和SQLite-net。我正在使用C#编程Windows 8.1应用程序。SQLite; “无法添加PRIMARY KEY列”-Exception
我所拥有的是以下几点:
模型:
public class Subject
{
[PrimaryKey, AutoIncrement]
public int Id { get; set; }
public string Name { get; set; }
}
而且OnLaunched-事件在App.Xaml.cs包含:
protected override void OnLaunched(LaunchActivatedEventArgs e)
{
[...]
// Get a reference to the SQLite database
DBPath = Path.Combine(
Windows.Storage.ApplicationData.Current.LocalFolder.Path, "Subjects.s3db");
// Initialize the database if necessary
using (var db = new SQLite.SQLiteConnection(DBPath))
{
// Create the tables if they don't exist
db.CreateTable<Subject>();
}
[...]
}
当我启动这个我在db.CreateTable()之后得到以下错误;被执行:
无法添加PRIMARY KEY列。
这里怎么回事?我真的很感谢你的帮助。
非常感谢。
问候,FunkyPeanut
不知道后,但不是你想创建一个已经存在的表? – 2013-11-24 16:57:35
嘿,感谢您的快速评论。那么我不知道,但我认为“CreateTable”表达式只创建一个表,如果它不存在。嗯....谢谢虽然! – FunkyPeanut
你最好检查一下。建立一个没有任何表的测试数据库,看看发生了什么。 – 2013-11-24 17:07:16