Git Product home page Git Product logo

sqliteef6migrations's People

Contributors

aaronamm avatar bubibubi avatar soar360 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

sqliteef6migrations's Issues

Duplicate index name generated

When I have a class that has two related collections, like so:

    public class Plant
    {
        public long Id { get; set; }

        public ICollection<Aggregate> Aggregates { get; set; }
        public ICollection<Spillway> Spillways { get; set; }
    }

It tries to create two indices with the same name, which fails like this:

 CREATE INDEX "IX_Plant_Id" ON "Aggregates" ("Plant_Id")
-- Executing at 3/20/2018 9:16:13 AM +01:00
-- Completed in 0 ms with result: 0

 CREATE INDEX "IX_Plant_Id" ON "Spillways" ("Plant_Id")
-- Executing at 3/20/2018 9:16:13 AM +01:00
-- Failed in 0 ms with error: SQL logic error
index IX_Plant_Id already exists

Exception thrown: 'System.Data.SQLite.SQLiteException' in EntityFramework.dll
An exception of type 'System.Data.SQLite.SQLiteException' occurred in EntityFramework.dll but was not handled in user code
SQL logic error
index IX_Plant_Id already exists

I guess adding a timestamp to the name to make it unique would fix the issue? Is there a workaround this, or do we have to wait for a new release?

Question

I'm trying migrations with your library. It's working OK with your example:

internal sealed class ContextMigrationConfiguration : DbMigrationsConfiguration<Context>
    {
        public ContextMigrationConfiguration()
        {
            AutomaticMigrationsEnabled = true;
            AutomaticMigrationDataLossAllowed = true;
            SetSqlGenerator("System.Data.SQLite", new SQLiteMigrationSqlGenerator());
        }
    }

But when I try to do this it fails:

public sealed class ContextMigrationConfiguration : DbMigrationsConfiguration<UnitOfWork>
    {
        private readonly bool _pendingMigrations;

        public ContextMigrationConfiguration()
        {
            AutomaticMigrationsEnabled = true;
            AutomaticMigrationDataLossAllowed = true;
            SetSqlGenerator("System.Data.SQLite", new SQLiteMigrationSqlGenerator());

            var migrator = new DbMigrator(this);
            _pendingMigrations = migrator.GetPendingMigrations().Any();
            
            if (_pendingMigrations)
            {
                migrator.Update();
                Seed(new UnitOfWork());
            }
        }

        protected sealed override void Seed(UnitOfWork context) 
        {
            // Initialization
        }
   }

_pendingMigrations = migrator.GetPendingMigrations().Any(); Fails with System.ObjectDisposedException on .GetPendingMigrations()

  | ObjectName | "SQLiteConnection"
  | Source | "System.Data.SQLite"

  | StackTrace | " en System.Data.SQLite.SQLiteConnection.CheckDisposed()\r\n en System.Data.SQLite.SQLiteConnection.get_State()\r\n en System.Data.Entity.Internal.RepositoryBase.CreateConnection()\r\n en System.Data.Entity.Migrations.History.HistoryRepository.QueryExists(String contextKey)\r\n en System.Data.Entity.Migrations.History.HistoryRepository.Exists(String contextKey)\r\n en System.Data.Entity.Migrations.History.HistoryRepository.GetPendingMigrations(IEnumerable`1 localMigrations)\r\n en System.Data.Entity.Migrations.DbMigrator.GetPendingMigrations()\r\n en QApps.DataLayer.Context.ContextMigrationConfiguration..ctor() en D:\Projects\...\Context\UnitOfWork.cs:línea 91"

I'm trying to init the db with some test data, but if I use Seed directly it set the data every time the app is launched, so I'm trying to Seed only after an update.

I will try the same question on StackOverflow just in case, any help will be apreciated.

Can't add a manual migration

I am using the latest System.Data.Sqlite.EF6 - version 1.118.0 (and the earliest I can find on Nigget is 1.115).
When trying to add a migration with add-migration I get:
PM> Add-Migration AddTotaPayloadLbs System.IO.FileLoadException: Could not load file or assembly 'System.Data.SQLite.EF6, Version=1.0.112.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040) File name: 'System.Data.SQLite.EF6, Version=1.0.112.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139' at System.Data.SQLite.EF6.Migrations.SQLiteMigrationSqlGenerator..ctor() at FSTRaK.Migrations.Configuration..ctor() in C:\Users\Oren\source\repos\FSTRAK\FSTRaK\Models\Entity\Migrations\Configuration.cs:line 15 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Data.Entity.Migrations.Utilities.MigrationsConfigurationFinder.FindMigrationsConfiguration(Type contextType, String configurationTypeName, Func2 noType, Func3 multipleTypes, Func3 noTypeWithName, Func3 multipleTypesWithName) at System.Data.Entity.Infrastructure.Design.Executor.GetMigrationsConfiguration(String migrationsConfigurationName) at System.Data.Entity.Infrastructure.Design.Executor.ScaffoldInternal(String name, DbConnectionInfo connectionInfo, String migrationsConfigurationName, Boolean ignoreChanges) at System.Data.Entity.Infrastructure.Design.Executor.Scaffold.<>c__DisplayClass0_0.<.ctor>b__0() at System.Data.Entity.Infrastructure.Design.Executor.OperationBase.<>c__DisplayClass4_01.b__0()
at System.Data.Entity.Infrastructure.Design.Executor.OperationBase.Execute(Action action)

WRN: Assembly binding logging is turned OFF.
To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1.
Note: There is some performance penalty associated with assembly bind failure logging.
To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog].

Could not load file or assembly 'System.Data.SQLite.EF6, Version=1.0.112.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
`

Not able to execute SQL commands from Migration Class

I am trying to execute some SQL commands using Sql() method from Up(). But, getting exception dialog when doing that, see the log window content below,

---------------------------
Assertion Failed: Abort=Quit, Retry=Debug, Ignore=Continue
---------------------------




   at System.Data.SQLite.EF6.Migrations.SQLiteMigrationSqlGenerator.GenerateSqlStatementConcrete(MigrationOperation migrationOperation)

   at System.Dynamic.UpdateDelegates.UpdateAndExecute2[T0,T1,TRet](CallSite site, T0 arg0, T1 arg1)

   at System.Data.SQLite.EF6.Migrations.SQLiteMigrationSqlGenerator.GenerateSqlStatement(MigrationOperation migrationOperation)

   at System.Data.SQLite.EF6.Migrations.SQLiteMigrationSqlGenerator.GenerateStatement(MigrationOperation migrationOperation)

   at System.Data.SQLite.EF6.Migrations.SQLiteMigrationSqlGenerator.Generate(IEnumerable`1 migrationOperations, String providerManifestToken)

   at System.Data.Entity.Migrations.DbMigrator.ExecuteOperations(String migrationId, VersionedModel targetModel, IEnumerable`1 operations, IEnumerable`1 systemOperations, Boolean downgrading, Boolean auto)

   at System.Data.Entity.Migrations.DbMigrator.ApplyMigration(DbMigration migration, DbMigration lastMigration)

   at System.Data.Entity.Migrations.DbMigrator.Upgrade(IEnume......

<truncated>
---------------------------
Abort   Retry   Ignore   
---------------------------

Since DropColumn is not supported, I was trying to achieve same using plain SQL command. Sample code listed below.

Sql(@"
                CREATE TABLE Tags_temp AS SELECT * FROM Tags;
                DROP TABLE Tags;
                ");

Setup info,

  <package id="EntityFramework" version="6.1.3" targetFramework="net461" />
  <package id="System.Data.SQLite" version="1.0.108.0" targetFramework="net461" />

Table Already Exists Error

I've tried to use this in my solution and opening a connection to an existing database with a new column to add tried to create an entire table that already existed. And its a table with no changes.

SQL logic error or missing database
table "Catalogs" already exists

Unable to add foreign key constraint

Hi,

I am having some trouble with the migration to sql lite which has schema defined :
Below is my Models

I have below Model"

  public abstract class BaseEntity
    {
        [Key]
        public int Id { get; set; }
    }
public class User: BaseEntity
    {
        public string FirstName { get; set; }
        public string LastName { get; set; }
        public string Email { get; set; }

        public virtual ICollection<Questions> Questions{ get; set; }
    }

  public class Questions: BaseEntity
    {
        public string Details { get; set; }
        public int UserId { get; set; }
        public virtual User User { get; set; }
    }

Db Context

public MyDbContext()
            : base("ConnectionStringName")
        {
            Database.SetInitializer(new MigrateDatabaseToLatestVersion<MyDbContext, Configuration>(true));
        }
        public DbSet<User> Users { get; set; }
        public DbSet<Device> Devices { get; set; }
        


        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            // Configure Code First to ignore PluralizingTableName convention 
            // If you keep this convention then the generated tables will have pluralized names. 
            modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
            modelBuilder.Entity<Device>()
                .HasRequired<User>(s => s.User)
                .WithMany(g => g.Devices)
                .HasForeignKey<int>(s => s.UserId);
        }

Migration configuration:
internal sealed class Configuration : DbMigrationsConfiguration
{
public Configuration()
{
AutomaticMigrationsEnabled = true;
AutomaticMigrationDataLossAllowed = true;
SetSqlGenerator("System.Data.SQLite", new SQLiteMigrationSqlGenerator());
}

I also tried putting ForeignKey attribute, but no luck

Everything comes properly in Database except the foreign key. The relationship is not defined in the sqllite DB.

And for me when I clone this project I was not able to build, was getting some nuget issues, so could not debug or run the example project.

Does below line means its is not supprted:
Relationships are not enforced with constraints

Connection string:

Source code for NuGet Pakage ver 104

Hello, @bubibubi !
Thank you so much for your work!
I am trying to use Nuget ver 1.0.104 for migrations. I have existing EF6 SQL migrations and trying to adopt them to SQLite. I have Issue when creating indexes in tables for Columns with the same name. I hoped I can change the source code to use Table Name in Index Name. But GitHub and Codeplex seems to have the source code for 102 version.
Could you help me please with this issue?
I will be happy to make a pull request with my changes.

Could you please clarify licence of this project?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.