Pomelo.entityframeworkcore.mysql: Test Scaffolding in 2.0.0-rtm-*

Created on 16 Aug 2017  路  10Comments  路  Source: PomeloFoundation/Pomelo.EntityFrameworkCore.MySql

Scaffolding has undergone many changes in 2.0. We are seeking help testing scaffolding in 2.0.0-rtm-* for the next week or so while we harden the 2.0 release

Most helpful comment

Thanks for the feedback on scaffolding everyone. If you are still having issues scaffolding in 2.0.0-rtm-* please open a new issue. We would like to release 2.0.0 on September 4th.

All 10 comments

Getting an error when running the scaffolding added on the readme for 2.0.0 preview.

The collection argument 'properties' must contain at least one element.

Seems like someone on SO is also getting it.
https://stackoverflow.com/questions/45714560/the-collection-argument-properties-must-contain-at-least-one-element-when-usi/45724933#45724933

In my project, the Scaffolding is failing in someone things and others work, for example:

Using migrations:

dotnet ef migrations add any

Generates correctly all migration files.

dotnet ef database update

Throws an exception in relation a table already created, but the database is empty.

I checked the Sql file generated with dotnet ef migrations script -o file.sql and it works directly in the database.

I tried the scaffolding command dotnet ef dbcontext scaffold "Server=localhost;User Id=root;Database=test" "Pomelo.EntityFrameworkCore.MySql" but It generated no tables.

It's pretty confuse, but I hope this information will help in something.

Environment data:
OS: WIndows 10
Dotnet version: 2.0.0
Pomelos' version: 2.0.0-rm-10056
MySql's version: 5.7.14

The scaffolding error is getting raised in class Check which is getting called from somewhere in class EntityType. If you comment out the call to GetConstraints() then it completes.

UPDATE: It appears that there is a new property called PrincipalColumns that may be required for DatabaseForeignKey class.

I have the same error like the github post, if I delete the foreign keys works

All, please try latest version 2.0.0-rtm-10057.

10057 has resolved the issue for me. Going to continue testing now.

@mguinness I was tried again with the new version, but something happens.

I was testing in a project with default Identity of .Net Core, and when I try to update the database from my migrations and a database empty, I get the next error:

Table 'aspnetroles' already exists

And in fact, in the info, appears the creation of model 2 times:

PS D:\Projectos\Test\Code\Test\Test.Administrator> dotnet ef database update
info: Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager[0]
      User profile is available. Using 'C:\Users\Koronos\AppData\Local\ASP.NET\DataProtection-Keys' as key repository and Windows DPAPI to encrypt keys at rest.
info: Microsoft.EntityFrameworkCore.Infrastructure[100403]
      Entity Framework Core 2.0.0-rtm-26452 initialized 'ApplicationDbContext' using provider 'Pomelo.EntityFrameworkCore.MySql' with options: None
info: Microsoft.EntityFrameworkCore.Infrastructure[100403]
      Entity Framework Core 2.0.0-rtm-26452 initialized 'ApplicationDbContext' using provider 'Pomelo.EntityFrameworkCore.MySql' with options: None
info: Microsoft.EntityFrameworkCore.Database.Command[200101]
      Executed DbCommand (16ms) [Parameters=[], CommandType='Text', CommandTimeout='0']
      SELECT 1 FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA='Test' AND TABLE_NAME='__EFMigrationsHistory';
info: Microsoft.EntityFrameworkCore.Database.Command[200101]
      Executed DbCommand (26ms) [Parameters=[], CommandType='Text', CommandTimeout='0']

                    SELECT CASE WHEN COUNT(*) = 0 THEN FALSE ELSE TRUE END
                    FROM information_schema.tables
                    WHERE table_type = 'BASE TABLE' AND table_schema = 'Test'
info: Microsoft.EntityFrameworkCore.Database.Command[200101]
      Executed DbCommand (0ms) [Parameters=[], CommandType='Text', CommandTimeout='0']
      SELECT CASE
          WHEN EXISTS (
              SELECT 1
              FROM `AspNetRoles` AS `a`)
          THEN TRUE ELSE FALSE
      END
info: Microsoft.EntityFrameworkCore.Database.Command[200101]
      Executed DbCommand (62ms) [Parameters=[], CommandType='Text', CommandTimeout='0']
      CREATE TABLE `__EFMigrationsHistory` (
          `MigrationId` varchar(95) NOT NULL,
          `ProductVersion` varchar(32) NOT NULL,
          CONSTRAINT `PK___EFMigrationsHistory` PRIMARY KEY (`MigrationId`)
      );
info: Microsoft.EntityFrameworkCore.Database.Command[200101]
      Executed DbCommand (0ms) [Parameters=[], CommandType='Text', CommandTimeout='0']
      SELECT 1 FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA='Test' AND TABLE_NAME='__EFMigrationsHistory';
info: Microsoft.EntityFrameworkCore.Database.Command[200101]
      Executed DbCommand (0ms) [Parameters=[], CommandType='Text', CommandTimeout='0']
      SELECT `MigrationId`, `ProductVersion`
      FROM `__EFMigrationsHistory`
      ORDER BY `MigrationId`;
info: Microsoft.EntityFrameworkCore.Migrations[200402]
      Applying migration '20170821031825_Initial'.
Applying migration '20170821031825_Initial'.
info: Microsoft.EntityFrameworkCore.Database.Command[200101]
      Executed DbCommand (7ms) [Parameters=[@__normalizedName_0='?' (Size = 256)], CommandType='Text', CommandTimeout='0']
      SELECT `r`.`Id`, `r`.`ConcurrencyStamp`, `r`.`Name`, `r`.`NormalizedName`
      FROM `AspNetRoles` AS `r`
      WHERE `r`.`NormalizedName` = @__normalizedName_0
      LIMIT 1
fail: Microsoft.EntityFrameworkCore.Database.Command[200102]
      Failed executing DbCommand (3ms) [Parameters=[], CommandType='Text', CommandTimeout='0']
      CREATE TABLE `AspNetRoles` (
          `Id` varchar(127) NOT NULL,
          `ConcurrencyStamp` longtext,
          `Name` varchar(256),
          `NormalizedName` varchar(256),
          CONSTRAINT `PK_AspNetRoles` PRIMARY KEY (`Id`)
      );
MySql.Data.MySqlClient.MySqlException (0x80004005): Table 'aspnetroles' already exists
   at MySql.Data.MySqlClient.MySqlDataReader.ActivateResultSet(ResultSet resultSet)
   at MySql.Data.MySqlClient.MySqlDataReader.<ReadFirstResultSetAsync>d__64.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at MySql.Data.MySqlClient.MySqlDataReader.<CreateAsync>d__63.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at MySql.Data.MySqlClient.CommandExecutors.TextCommandExecutor.<ExecuteReaderAsync>d__3.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at MySql.Data.MySqlClient.CommandExecutors.TextCommandExecutor.<ExecuteNonQueryAsync>d__1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at MySql.Data.MySqlClient.MySqlCommand.ExecuteNonQuery()
   at Microsoft.EntityFrameworkCore.Storage.Internal.MySqlRelationalCommand.<ExecuteAsync>d__3.MoveNext()
Failed executing DbCommand (3ms) [Parameters=[], CommandType='Text', CommandTimeout='0']
CREATE TABLE `AspNetRoles` (
    `Id` varchar(127) NOT NULL,
    `ConcurrencyStamp` longtext,
    `Name` varchar(256),
    `NormalizedName` varchar(256),
    CONSTRAINT `PK_AspNetRoles` PRIMARY KEY (`Id`)
);

But, the same project works if I run the project (with a database empty) using context.Database.EnsureCreatedAsync(); in my Configure function.

@Koronos, you cannot work with migration anymore if you have scaffolded. And you can also work without EnsureCreated. Because your database does not have a migration history, and your tables has been already created. Migrations should be used in code first scenario. You are in the db first scenario, so modify the database first and re-scaffold again.

@Kagamine I'm using it in code first scenario. I did the test ever with the database empty (no tables, no data), but the command tries to create the table 2 times.

With EnsureCreatedAsync creates correctly the scheme in the first run with the table clean (No tables, no data).

Let me check if this happens in a clean project.

Update: I was checked in a clean project and all commands work well. I will check more in detail what is happen. If I find something I will comment here.

Thanks for the feedback on scaffolding everyone. If you are still having issues scaffolding in 2.0.0-rtm-* please open a new issue. We would like to release 2.0.0 on September 4th.

Was this page helpful?
0 / 5 - 0 ratings