今天我已經開始應對數據庫。我已經安裝了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