4
Answers

getting error when add migration in mvc core

Garima Bansal

Garima Bansal

2y
821
1

I am adding migration in my project but getting this error, i am using VS 20, already added first migration but now i want create new database table but getting this error

 

add-migration Registration
add-migration : The term 'add-migration' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the 
spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ add-migration Registration
+ ~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (add-migration:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

Answers (4)
1
Sachin Singh

Sachin Singh

11 55.8k 87.1k 2y

You need to install latest .NET sdk or vs2022

1
Garima Bansal

Garima Bansal

982 736 46.8k 2y

Sachin Singh

 

if i try to install microsoft.entityframeworkcore.tools then it give error


Error    NETSDK1045    The current .NET SDK does not support targeting .NET 6.0.  Either target .NET 5.0 or lower, or use a version of the .NET SDK that supports .NET 6.0.    AgricultureApex    C:\Program Files\dotnet\sdk\5.0.415\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.TargetFrameworkInference.targets    141    
 

1
Sachin Singh

Sachin Singh

11 55.8k 87.1k 2y

Make sure microsoft.entityframeworkcore.tools is installed. 

1
Garima Bansal

Garima Bansal

982 736 46.8k 2y

somehow , i try to add migration and it created

add-migration Register
Build started...
Build succeeded.
Microsoft.EntityFrameworkCore.Infrastructure[10403]
      Entity Framework Core 6.0.0 initialized 'AgricultureContext' using provider 'Microsoft.EntityFrameworkCore.SqlServer:6.0.0' with options: None

but nothing created in migration class

using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace AgricultureApex.Migrations
{
    public partial class Register : Migration
    {
        protected override void Up(MigrationBuilder migrationBuilder)
        {

        }

        protected override void Down(MigrationBuilder migrationBuilder)
        {

        }
    }
}
 

and then if i use command Remove-migration then it give this issue

remove-migration
Build started...
Build succeeded.
Microsoft.EntityFrameworkCore.Infrastructure[10403]
      Entity Framework Core 6.0.0 initialized 'AgricultureContext' using provider 'Microsoft.EntityFrameworkCore.SqlServer:6.0.0' with options: None
Microsoft.EntityFrameworkCore.Database.Command[20101]
      Executed DbCommand (45ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
      SELECT 1
Microsoft.EntityFrameworkCore.Database.Command[20101]
      Executed DbCommand (34ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
      SELECT OBJECT_ID(N'[__EFMigrationsHistory]');
Microsoft.EntityFrameworkCore.Database.Command[20101]
      Executed DbCommand (8ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
      SELECT [MigrationId], [ProductVersion]
      FROM [__EFMigrationsHistory]
      ORDER BY [MigrationId];
The migration '20221222085450_PhysicalIndicesValueColumn' has already been applied to the database. Revert it and try again. If the migration has been applied to other databases, consider reverting its changes using a new migration instead.