Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SQLite.SQLiteException: duplicate column name #435

Closed
newtoncw opened this issue Jul 14, 2016 · 7 comments
Closed

SQLite.SQLiteException: duplicate column name #435

newtoncw opened this issue Jul 14, 2016 · 7 comments
Assignees
Labels

Comments

@newtoncw
Copy link

newtoncw commented Jul 14, 2016

I'm having the following error in my application, using Xamarin in Android: SQLite.SQLiteException: duplicate column name IdSettings.

Here is my code:

private Database()
{  
            this.connection = new SQLiteConnection(DatabasePath);

        this.Connection.CreateTable<Settings>();
        this.Connection.CreateTable<Profile>();
        this.Connection.CreateTable<Stat>();
        this.Connection.CreateTable<Crest>();
        this.Connection.CreateTable<MatchTeam>();
        this.Connection.CreateTable<Match>();
        this.Connection.CreateTable<Media>();
        this.Connection.CreateTable<DbInfo>();

}

And here is the stack trace from Android:

java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:703)
Caused by: java.lang.reflect.InvocationTargetException
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:372)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:908)
    ... 1 more
Caused by: md52ce486a14f4bcd95899665e9d932190b.JavaProxyThrowable: SQLite.SQLiteException: duplicate column name: IdSettings
  at SQLite.SQLite3.Prepare2 (SQLitePCL.sqlite3 db, System.String query) [0x0001e] in <filename unknown>:0 
  at SQLite.SQLiteCommand.Prepare () [0x00011] in <filename unknown>:0 
  at SQLite.SQLiteCommand.ExecuteNonQuery () [0x00012] in <filename unknown>:0 
  at SQLite.SQLiteConnection.Execute (System.String query, System.Object[] args) [0x00040] in <filename unknown>:0 
  at SQLite.SQLiteConnection.MigrateTable (SQLite.TableMapping map) [0x000db] in <filename unknown>:0 
  at SQLite.SQLiteConnection.CreateTable (System.Type ty, CreateFlags createFlags) [0x00176] in <filename unknown>:0 
  at SQLite.SQLiteConnection.CreateTable[T](CreateFlags createFlags) [0x00000] in <filename unknown>:0 
  at FifaSeasons.Entities.Database..ctor () [0x0001d] in <filename unknown>:0 
  at FifaSeasons.Entities.Database.get_Instance () [0x00022] in <filename unknown>:0 
  at FifaSeasons.Entities.Settings.Load () [0x00000] in <filename unknown>:0 
  at FifaSeasons.App..ctor () [0x00006] in <filename unknown>:0 
  at FifaSeasons.Droid.MainActivity.OnCreate (Android.OS.Bundle bundle) [0x00023] in <filename unknown>:0 
  at Android.App.Activity.n_OnCreate_Landroid_os_Bundle_ (IntPtr jnienv, IntPtr native__this, IntPtr native_savedInstanceState) [0x00011] in <filename unknown>:0 
  at (wrapper dynamic-method) System.Object:77f7d68d-0e63-4fa1-ba05-91ac6f4e8d28 (intptr,intptr,intptr)
    at md57f9709086b0c248507ed1071a2b22cc2.MainActivity.n_onCreate(Native Method)
    at md57f9709086b0c248507ed1071a2b22cc2.MainActivity.onCreate(MainActivity.java:28)
    at android.app.Activity.performCreate(Activity.java:6021)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2284)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2391)
    at android.app.ActivityThread.access$800(ActivityThread.java:151)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1309)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:135)
    at android.app.ActivityThread.main(ActivityThread.java:5354)
    ... 4 more

This occurs in the first run of the application, and I think that the method MigrateTable should not run.

@masterjs
Copy link

I'm also getting the same error with a very simple class

@newtoncw
Copy link
Author

Problem solved!
In Android Options, I set linker to Sdk Assemblies Only.

@masterjs
Copy link

Thanks for the suggestion newtoncw, but setting Sdk Assemblies Only was not an option for us. So I instead went with a Execute that will do an explicit CREATE Table. This works well on all platforms.

@kyluke
Copy link

kyluke commented Oct 26, 2016

@masterjs how did you do that? Did you manually write out SQL queries?

@trevoriancox
Copy link

I am seeing this issue still. Link SDK assemblies only works for me too, so there must be something we need to preserve in the linking.

@trevoriancox
Copy link

This is still not a great solution but:

<AndroidLinkSkip>SQLite-net;SQLitePCL.raw</AndroidLinkSkip>

from:
https://forums.xamarin.com/discussion/65328/sqlite-duplicate-column-name-exception-on-device-but-not-on-simulator

@praeclarum praeclarum added the Bug label Aug 5, 2017
@praeclarum
Copy link
Owner

I will try adding the [Preserve] attribute to the assembly to help, but first I need to repro.

https://developer.xamarin.com/guides/ios/advanced_topics/linker/#Preserving_Code

@praeclarum praeclarum self-assigned this Aug 5, 2017
github-actions bot pushed a commit to Reddevildragg-UPM-Forks/sqlite-net that referenced this issue Nov 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants