question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

SQLite.SQLiteException: duplicate column name

See original GitHub issue

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.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
praeclarumcommented, Aug 5, 2017

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

0reactions
trevoriancoxcommented, May 5, 2017

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

Duplicate column name on SQLite upgrade for a new column
I've been getting an inconsistent, non-reproducible crash upon users upgrading to a new version of the local SQLite DB when updating the app....
Read more >
ALTER TABLE ADD COLUMN problem
As things stand, with "duplicate column" I get error numner 1 (generic error, not too useful) and a message such as "duplicate column...
Read more >
SQLiteException - Duplicate column name [227231447]
I am assuming it happens because I use on-demand initialization of the WorkManager (faster app startup times) and my app is multi-process (main ......
Read more >
SQLite.SQLiteException: duplicate column name id in v1. ...
This works fine up to v1.3.2 but in v1.3.3 it causes an SQLite.SQLiteException: duplicate column name id. I'm using current Visual Studio ...
Read more >
crash in android.database.sqlite.SQLiteException ...
SQLiteException : duplicate column name: touchIcon (code 1): , while compiling: ALTER TABLE metadata ADD COLUMN touchIcon STRING at android.database.sqlite.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found