C # and MySQL with AspNetUsers, tables deleted

2

I'm developing a system with C # (MVC) and MySQL. Everything works perfectly fine when I use my local instance of the Database.

I've duplicated this database on UolHost and that's where something bizarre happens. When I change the connection string (just the address) to connect to the UolHost database, when trying to login to the system, all the database tables are deleted and new AspNetUsers tables are automatically created.

Why is the system erasing the database and building only these tables? And why does this only happen in the server database, while on the machine it works normally?

Someone, please, have a tip?

    
asked by anonymous 30.07.2015 / 02:24

2 answers

1

I think you should be using EntityFramework. This bizarre thing may come from it, because of the configuration when initializing a database. You have four options for initializing the database:

  • CreateDatabaseIfNotExists - This is the default , and creates the database if it does not exist
  • DropCreateDatabaseIfModelChanges - This mode dropa the complete database if the templates have been modified.
  • DropCreateDatabaseAlways - This fashion dropa the complete database
  • Custom - You can create your own initializer if one of these does not satisfy
  • Make sure you are using something like DropCreateDatabaseIfModelChanges , as it is able to find the templates changed when you change your connection string .

    Look for a function called:

    .SetInitializer<T>()
    
        
    31.07.2015 / 07:23
    1

    The problem was that the __migrationhistory table was capitalized on the database ... and since it was not found in InitializeDatabase, it cleaned and rebuilt!

    var migrationHistoryTableExists = ((IObjectContextAdapter)context).ObjectContext.ExecuteStoreQuery<int>(
                string.Format(
                  "SELECT COUNT(*) FROM information_schema.tables WHERE table_schema = '{0}' AND table_name = '__migrationhistory'",
                  "superacrm"));
    
                // if MigrationHistory table is not there (which is the case first time we run) - create it
                if (migrationHistoryTableExists.FirstOrDefault() == 0)
                {
                    context.Database.Delete();
                    context.Database.Create();
                }
    
        
    01.08.2015 / 18:09