Difference between revisions of "EF Core error"
From Logic Wiki
(Created page with "Category:EntityFramework Category:MVC Couldn't find the solution for these <pre> Add-Migration : Exception calling "Substring" with "1" argument(s): "StartIndex can...") |
|||
| (One intermediate revision by the same user not shown) | |||
| Line 2: | Line 2: | ||
[[Category:MVC]] | [[Category:MVC]] | ||
| − | + | == Problem == | |
| − | + | When I run Add-Migration or update-database commands in PM I get these errors. | |
| − | + | ||
<pre> | <pre> | ||
Add-Migration : Exception calling "Substring" with "1" argument(s): "StartIndex cannot be less than zero. | Add-Migration : Exception calling "Substring" with "1" argument(s): "StartIndex cannot be less than zero. | ||
| Line 13: | Line 12: | ||
+ CategoryInfo : NotSpecified: (:) [Add-Migration], MethodInvocationException | + CategoryInfo : NotSpecified: (:) [Add-Migration], MethodInvocationException | ||
+ FullyQualifiedErrorId : ArgumentOutOfRangeException,Add-Migration | + FullyQualifiedErrorId : ArgumentOutOfRangeException,Add-Migration | ||
| + | </pre> | ||
| + | |||
| + | == 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 == | ||
| + | <pre> | ||
| + | CREATE TABLE `__EFMigrationsHistory` | ||
| + | ( | ||
| + | `MigrationId` nvarchar(150) NOT NULL, | ||
| + | `ProductVersion` nvarchar(32) NOT NULL, | ||
| + | PRIMARY KEY (`MigrationId`) | ||
| + | ); | ||
</pre> | </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`)
);