Difference between revisions of "EF Core error"

From Logic Wiki
Jump to: navigation, search
 
Line 22: Line 22:
  
 
It works and does the job but it also displays this error.
 
It works and does the job but it also displays this error.
 +
 +
== Problem : No Migration Table Exists ==
 +
if you get an error like this in MySql it means migration table is not automatically created
 +
 +
== Solution ==
 +
<pre>
 +
CREATE TABLE `__EFMigrationsHistory`
 +
(
 +
    `MigrationId` nvarchar(150) NOT NULL,
 +
    `ProductVersion` nvarchar(32) NOT NULL,
 +
    PRIMARY KEY (`MigrationId`)
 +
);
 +
</pre>

Latest revision as of 13:28, 5 August 2020


Problem

When I run Add-Migration or update-database commands in PM I get these errors.

Add-Migration : Exception calling "Substring" with "1" argument(s): "StartIndex cannot be less than zero.
Parameter name: startIndex"
At line:1 char:1
+ Add-Migration -Name 'Firstqa' -verbose
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Add-Migration], MethodInvocationException
    + FullyQualifiedErrorId : ArgumentOutOfRangeException,Add-Migration

Explanation

When the project structured like

  • .NET CORE
  • MySql (SapientGuardian)
  • StructureMap

Structuremap obviously try to auto fill an interface in a constructor in MySql EF code ..

It works and does the job but it also displays this error.

Problem : No Migration Table Exists

if you get an error like this in MySql it means migration table is not automatically created

Solution

CREATE TABLE `__EFMigrationsHistory` 
( 
    `MigrationId` nvarchar(150) NOT NULL, 
    `ProductVersion` nvarchar(32) NOT NULL, 
     PRIMARY KEY (`MigrationId`) 
);