Code First Migrations Mysql - Specify the '-Verbose' flag to view the SQL statements being Applied to the target database

Asked

Viewed 1,027 times

3

I am creating a web application in C# and because of the hosting server, the database is in Mysql. Then I installed Mysql.Data.Entity, EF6, enabled Migrations, added the Migrations class, but when giving the Update-database -Verbose returns the message:

Specify the '-Verbose' flag to view the SQL statements being Applied to the target database.

As I already have Easyphp installed, I am using Mysql already in it!

Context:

public DBContexto() : base("Contexto") { }
    public DbSet<Pessoa> Pessoas { get; set; }
    protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {
        modelBuilder.Conventions.Remove();
        modelBuilder.Conventions.Remove();
    }

Conection String:<?xml version="1.0" encoding="utf-8" ?> <configuration> <configSections> <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=4.4.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" /> </configSections> <connectionStrings> <add name="Contexto" connectionString="Data Source=127.0.0.1:3306;Database=dbyou;Id=root;Password=;" providerName="MySql.Data.MySqlClient" /> </connectionStrings> <entityFramework> <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework"> <parameters> <parameter value="v11.0" /> </parameters> </defaultConnectionFactory> </entityFramework> </configuration>

1 answer

3


This is a standard message stating that by adding the Verbose flag you will see which SQL queries are running on the applied Migration, if you only received this message you can rest assured that no error has occurred.

Add the annotation above the context class:

 [DbConfigurationType(typeof(MySqlEFConfiguration))]
 public class SeuContexto{

    public SeuContexto()
        : base(/*AQUI DEVE ESTAR O NOME DA CONEXÃO DO CONNECTION STRING*/)
    {        
    }

Make sure that in web.config or app.config you have your Mysql string Connection, if you don’t have it add and reference it in the context base.

Maybe the reason you’re not saving is here:

    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
  <parameters>
    <parameter value="v11.0" />
  </parameters>
</defaultConnectionFactory>

Because he’s using Localdb’s connectionFactory, change to:

<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
<providers>
  <provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, 
    MySql.Data.Entity.EF6" />
  <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, 
    EntityFramework.SqlServer" />
</providers>

Follow the link to a problem similar to yours: https://stackoverflow.com/questions/20277677/dynamic-mysql-database-connection-for-entity-framework-6

  • The problem is that it is not creating the Tables in the Bank! and when I try to do via Data Model, the SQL connector does not appear, although I have installed it

  • 1

    Voce used the "add-Migration XX" command? Where XX is a name of your choice to enumerate Migration

  • I did. But he doesn’t create the tables!

  • 1

    check in your app.config or web.config the database string Connection, may be saving in the default database of the project, go to View>Sql Object Viewer (I don’t remember the name exactly), doing this will open a field on the left of the visual studio, check the databases present there and if any were created

  • Connection String is targeting my Mysql database: localhost:3306. dai on my server, I went to create a Mysql connection, but only appears from SQL Server and Oracle. It does not appear from Mysql, but I installed NET Connector

  • 1

    Check in the context class constructor of the Entity framework, there is written which connection it is using (inheriting), as when running the update-database it presents no error the table is being created, you just have to figure out where

  • I’m using Context and the Conection string created! I just don’t know where it’s being created then! in the SQL shown in the verbose, it uses dbo.Person, so it’s using Sqlserver? if yes, how could I be directing Mysql in Connectionstring

  • 1

    Please supplement your question with an excerpt from the context code, thank you

  • I did a test. I added a file, then searched it and it worked! I mean, it’s creating a table!

  • 1

    Go to View>Server Explorer check all the servers, update the pages, it has to be somewhere there, or it could be in some db local, check the project folders for a file. mdf

  • I believe that changing the XML as I changed the answer will make it work this time, if my answer solves your problem please mark it as the solution, thank you

Show 6 more comments

Browser other questions tagged

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