Open DevJonny opened 4 years ago
I'll take a look at this
@DevJonny how are we handling ADD FOREIGN KEY
operations? Specifically adding SubFactionId
to the Members
table...
System.NotSupportedException: SQLite does not support this migration operation ('AddForeignKeyOperation'). For more information, see http://go.microsoft.com/fwlink/?LinkId=723262.
at Microsoft.EntityFrameworkCore.Migrations.SqliteMigrationsSqlGenerator.Generate (Microsoft.EntityFrameworkCore.Migrations.Operations.AddForeignKeyOperation operation, Microsoft.EntityFrameworkCore.Metadata.IModel model, Microsoft.EntityFrameworkCore.Migrations.MigrationCommandListBuilder builder) [0x00010] in <6fac96ba37a44740bc51ba823588ec81>:0
at Microsoft.EntityFrameworkCore.Migrations.MigrationsSqlGenerator+<>c.<.cctor>b__72_1 (Microsoft.EntityFrameworkCore.Migrations.MigrationsSqlGenerator g, Microsoft.EntityFrameworkCore.Migrations.Operations.MigrationOperation o, Microsoft.EntityFrameworkCore.Metadata.IModel m, Microsoft.EntityFrameworkCore.Migrations.MigrationCommandListBuilder b) [0x00000] in <1b06b8e99d984506b89b3e4ae11831eb>:0
at Microsoft.EntityFrameworkCore.Migrations.MigrationsSqlGenerator.Generate (Microsoft.EntityFrameworkCore.Migrations.Operations.MigrationOperation operation, Microsoft.EntityFrameworkCore.Metadata.IModel model, Microsoft.EntityFrameworkCore.Migrations.MigrationCommandListBuilder builder) [0x00045] in <1b06b8e99d984506b89b3e4ae11831eb>:0
at Microsoft.EntityFrameworkCore.Migrations.MigrationsSqlGenerator.Generate (System.Collections.Generic.IReadOnlyList`1[T] operations, Microsoft.EntityFrameworkCore.Metadata.IModel model) [0x0002d] in <1b06b8e99d984506b89b3e4ae11831eb>:0
at Microsoft.EntityFrameworkCore.Migrations.SqliteMigrationsSqlGenerator.Generate (System.Collections.Generic.IReadOnlyList`1[T] operations, Microsoft.EntityFrameworkCore.Metadata.IModel model) [0x00007] in <6fac96ba37a44740bc51ba823588ec81>:0
at Microsoft.EntityFrameworkCore.Migrations.Internal.Migrator.GenerateUpSql (Microsoft.EntityFrameworkCore.Migrations.Migration migration) [0x00045] in <1b06b8e99d984506b89b3e4ae11831eb>:0
at Microsoft.EntityFrameworkCore.Migrations.Internal.Migrator+<>c__DisplayClass13_2.<GetMigrationCommandLists>b__2 () [0x00026] in <1b06b8e99d984506b89b3e4ae11831eb>:0
at Microsoft.EntityFrameworkCore.Migrations.Internal.Migrator.Migrate (System.String targetMigration) [0x0007a] in <1b06b8e99d984506b89b3e4ae11831eb>:0
at Microsoft.EntityFrameworkCore.RelationalDatabaseFacadeExtensions.Migrate (Microsoft.EntityFrameworkCore.Infrastructure.DatabaseFacade databaseFacade) [0x00010] in <1b06b8e99d984506b89b3e4ae11831eb>:0
at KillTeam.Services.KTUserContext..ctor (System.String dbpath) [0x00009] in /Users/steven/source/KTManager/KTManagerApp/KillTeam/Services/KTUserContext.cs:16
at KillTeam.Services.DBUpdater..ctor (System.String dbpath, KillTeam.Services.RulesProviders.RulesProvider provider, System.EventHandler`1[TEventArgs] callback) [0x00028] in /Users/steven/source/KTManager/KTManagerApp/KillTeam/Services/DBUpdater.cs:43
at KillTeam.Services.KTContext+<>c.<.cctor>b__6_0 () [0x00000] in /Users/steven/source/KTManager/KTManagerApp/KillTeam/Services/KTContext.cs:23
at System.Lazy`1[T].ViaFactory (System.Threading.LazyThreadSafetyMode mode) [0x00043] in /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/external/corefx/src/Common/src/CoreLib/System/Lazy.cs:333
at System.Lazy`1[T].ExecutionAndPublication (System.LazyHelper executionAndPublication, System.Boolean useDefaultConstructor) [0x00022] in /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/external/corefx/src/Common/src/CoreLib/System/Lazy.cs:351
at System.Lazy`1[T].CreateValue () [0x00074] in /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/external/corefx/src/Common/src/CoreLib/System/Lazy.cs:431
at System.Lazy`1[T].get_Value () [0x00000] in /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/external/corefx/src/Common/src/CoreLib/System/Lazy.cs:509
at KillTeam.Services.KTContext.get_Db () [0x00000] in /Users/steven/source/KTManager/KTManagerApp/KillTeam/Services/KTContext.cs:16
at KillTeam.ViewModels.DatabaseLoadViewModel.UpdateDB () [0x00013] in /Users/steven/source/KTManager/KTManagerApp/KillTeam/ViewModels/DatabaseLoadViewModel.cs:28
at KillTeam.ViewModels.DatabaseLoadViewModel.<StartUpdate>b__4_0 (System.Object _o) [0x00000] in /Users/steven/source/KTManager/KTManagerApp/KillTeam/ViewModels/DatabaseLoadViewModel.cs:22
at System.Threading.QueueUserWorkItemCallback.WaitCallback_Context (System.Object state) [0x0000d] in /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/mcs/class/referencesource/mscorlib/system/threading/threadpool.cs:1370
at System.Threading.ExecutionContext.RunInternal (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) [0x00071] in /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/mcs/class/referencesource/mscorlib/system/threading/executioncontext.cs:968
at System.Threading.ExecutionContext.Run (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) [0x00000] in /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/mcs/class/referencesource/mscorlib/system/threading/executioncontext.cs:910
at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem () [0x00021] in /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/mcs/class/referencesource/mscorlib/system/threading/threadpool.cs:1341
at System.Threading.ThreadPoolWorkQueue.Dispatch () [0x00074] in /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/mcs/class/referencesource/mscorlib/system/threading/threadpool.cs:899
at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback () [0x00000] in /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/mcs/class/referencesource/mscorlib/system/threading/threadpool.cs:1261
@sklarsa I think the only way to add a new Foreign Key with SQLite is by adding the actual SQL as an operation in the migration file. Basically you have to create a new table (with the new FK), copy across the data, and drop the old table according to this KB article.
I wish we weren't using a relational DB for this, but that's what we're stuck with for now.
@DevJonny Do you have a copy of the SQLite database that you can send over? Android device monitor is crashing whenever I open it, so I can't get to my emulator's filesystem
@sklarsa I'll see if I can get one this evening.
Thanks! I started working on a raw sql script to execute during migrations, but it was painful to write. Maybe I'll try something along these lines next, https://github.com/dotnet/efcore/issues/329#issuecomment-276138743
Yeah that looks like a good shout 👍
I'm going to split this up into a few PRs
The first PR is ready https://github.com/KTManager/KTManagerApp/pull/131
Describe the solution you'd like I want to be able to select the sub-factions introduced in the Elites book
Describe alternatives you've considered Battlescribe ;)