SQLite的Xamarin重复列ID发布

问题描述:

var path = System.IO.Path.Combine (App.DEVICE_LOCAL_FOLDER, "database.db3"); 
      _database = new SQLiteAsyncConnection (path); 
      _database.CreateTableAsync<Setting>().Wait(); 
      _database.CreateTableAsync<Authentication>().Wait(); 

此代码应用程序启动时执行了我的Xamarin.Forms的应用程序,每次我的应用程序启动时,我得到“消息‘重复的列名:setting_id’串”。我删除了调试设备并从头开始启动,以确保重复的表或类似的东西没有被创建。我的“设置”模型看起来像这样。SQLite的Xamarin重复列ID发布

using SQLite; 
namespace namespace 
{ 
    public class Setting 
    { 
     [PrimaryKey, AutoIncrement] 
     public int setting_id { get; set; } 
     public string field1 { get; set; } = 
      ""; 
     public string field2 { get; set; } = ""; 
     public string emailOne { get; set; } = ""; 
     public string emailTwo { get; set; } = ""; 
     public string field3 { get; set; } = ""; 
     public string field4 { get; set; } = ""; 
     public Setting() 
     { 

     } 
    } 
}  

使用Xamarin.Forms版本2.2.0.45和sqlite-net-pcl版本1.1.2。目前我只在iOS上测试过它,它总是在应用程序启动时崩溃,未在Android上测试过。

+1

你在模拟器上检查过吗?看到[这个论坛帖子](https://forums.xamarin.com/discussion/65328/sqlite-duplicate-column-name-exception-on-device-but-not-on-simulator)寻找可能的解决方案 –

+0

@GeraldVersluis我认为这可能是解决方案,我记得最近将“全部链接”设置为我的程序集设置。我会确认并回复。谢谢! –

感谢Gerald Versluis,解决方案是确保我的程序集没有全部链接,一旦切换,然后链接到“SDK Assemblies Only”,问题就解决了。