C# and Mysql with Aspnetusers, deleted tables

Asked

Viewed 108 times

2

I am developing a system with C# (MVC) and Mysql. Everything works perfectly well when using my local database instance.

I duplicated this database on Uolhost and that’s when something bizarre happens. When I change the Connection string (only the address) to connect to the Uolhost database, when trying to log into the system, all the database tables are deleted and new tables are created AspNetUsers automatically.

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

Someone, please, would have a hint?

  • You are using Simple Membership?

  • Does this situation occur after you publish the site? Make sure you are not sending the database more than once.

  • I don’t even get to publish... just from running on VS it already happens...

  • Gypsy, I’m using the authentication that VS itself puts on when you create the project...

2 answers

1

I think it must be using the Entityframework. This bizarre thing may come from it, because of the configuration when initializing a database. You have four options to initialize the database:

  1. Createdatabaseifnotexists - That’s the default, and creates the database if there is no
  2. DropCreateDatabaseIfModelChanges - That way droplet the complete database if the models have been modified.
  3. Dropcreatedatabasealways - That fashion droplet the complete database at all times.
  4. Personalized - You can create your own initializer if one of these does not satisfy

Make sure you’re using something like DropCreateDatabaseIfModelChanges, because the system is able to think that the models changed when you change your Connection string.

Look for a function called:

.SetInitializer<T>()
  • 1

    It wasn’t quite that, but your tip helped me find out!!! Thanks!!!

  • @Felipebulle Good! If you want, you can post an answer with which was the solution even!

1

The problem was that the __migrationhistory table was capitalized in the bank... and as it was not found in Initializedatabase, it was cleaned and created again!

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();
            }

Browser other questions tagged

You are not signed in. Login or sign up in order to post.