-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can't Enable-Migrations or Add-Migration : The term 'xxx' is not recognized as the name of a cmdlet #1196
Comments
To get started, check out my post on Entity Framework 7 Migrations in ASP.NET vNext |
Thanks for your help ! I still have an error, but it's evolving !
I'm sure i miss something, but after long search everywhere, I don't find what... Just in case, here is my project.json {
"version": "1.0.0-*",
"dependencies": {
"EntityFramework": "7.0.0-*",
"EntityFramework.SqlServer": "7.0.0-*",
"EntityFramework.Commands": "7.0.0-*"
},
"commands": {
"run": "run",
"ef": "EntityFramework.Commands"
},
"frameworks": {
"aspnet50": { },
"aspnetcore50": {
"dependencies": {
"System.Console": "4.0.0-*"
}
}
}
} |
Now you're seeing a bug that was fixed yesterday by #1182. Try again with the latest nightly. |
Thanks, but it looks like i'm cursed...
|
Ok so after searching everything and everywhere, i think i've find my issue... It seems to be a problem (or maybe i'm the problem...) with kvm. When i run
What I understand is that I have to target I've finally changed manually my PATH to use Hope it can help someone. |
Closing since everything seems to be working now. |
@bricelam your blog doesn't work.
|
Figured it out:
|
@egorpavlikhin - correct, we match that method by convention. We do have an item to make all this more robust by RTM. |
Hey I just want to clarify something here. I'm NOT using aspnet5 but instead a basic full .NET app ..console (and yes, I understand that it's not recommended, I'm just using that to explore) Instead of having a paramterless ctor on dbcontext and specifying UseSqlServer with connection string in onconfiguration, I am passing in the dbcontextoptions. So in this scenario, if I am not using d.i., I won't succeed with migrations, right? Therefore if I just want to show how you could continue to use migrations in a familiar way, I either have to use DI (on my own since not using aspnet5 or mvc etc) or I have to just go back to the "not grown up" pattern of usesqlserver with connection string in onconfiguring, right? |
Hi, I still get this error with the latest version.
I can provide whatever code is need. I have been googling for 3 hours on this and nothing helped. |
I haven't done it in a few weeks, but have not had any problems with k ef migrations. The fact that it says no migrator registered makes me wonder if you've specified the provider somewhere. If not, here are ways to do that in an aspnet5 app: https://github.com/aspnet/EntityFramework/wiki/Configuring-a-DbContext#dependency-injection-scenarios |
Did you ever get this fixed @AngelVenchev ? I'm not getting this bug locally, but when I deploy to azure though git I get it. |
@0xdeafcafe I fixed it when I implemented with another configuration from @julielerman 's link. I am not really sure what caused though |
I'm assuming this currently also does not work if your context is elsewhere than the Web project. I don't like having the context and EF code in my web project so it usually moves into some Service assembly. In EF6 this is kind of similar where you have to make your web project the default startup, but tell the Package Manager console that you're targeting the assembly with the DbContext in it. There doesn't seem to be an equivalent right now for k ef, is that accurate? It complains theres no context if I run it in the web project folder and won't even recognize the k ef command in the services project folder, despite the Commands assembly being referenced there. I understand it's a work in progress, I'm just trying to confirm that I'm not missing anything. POST BREAK EDIT: After poking around I realized I had to add the ef command to project.json myself, as is done for us in the web template. The second step was to temporarily put my connection string as part of the UseSqlServer call on OnConfiguring call which is not ideal but works just fine if I just need to generate a migration. After that, k ef migration add did exactly what I wanted, thanks for all the hard work! |
Ran into this same issue as Vassi with ASP.NET 5 and using a separate project for EF. Currently there seems to be no way to refer to the connection string defined in the web project's config file when running migrations from the command line. My latest problem with CTP6 and a standard sample ASP.NET 5 project (after hard-coding the connection string) is that migrations are failing with "ALTER TABLE DROP COLUMN failed because column 'NormalizedEmail-' does not exist in table AspNetUsers. Not sure why that's happening... UPDATE: The migration k ef migration add foo created included a bunch of things relating to aspnetusers that were wonky/wrong and unrelated to the model class I had added. I removed all of that from the migration, leaving just my CREATE TABLE / DROP TABLE statements for my new entity, and everything worked. |
@ardalis - That latest issue is a bug with the scaffolded code. @bricelam is working on a fix... but in the meantime you just need to fix the scaffolded code to make sure it gets the right overload of |
@ardalis - Should also mention that we don't pick up Startup.cs from another project yet... so hardcoding connection string in UseSqlServer in OnConfiguring is the correct workaround. |
@rowanmiller if I hardcode the connection string, I won't be able to publish to azure and use a different database. |
I had this issue @luisrudge, what I did was check if protected override void OnConfiguring(DbContextOptions options)
{
var config = Startup.Configuration
?? new Configuration()
.AddJsonFile("config.json")
.AddEnvironmentVariables();
options.UseSqlServer(config.Get("Data:DefaultConnection:ConnectionString"));
} |
Awesome @0xdeafcafe Thanks! |
Try the following steps:
"Microsoft.EntityFrameworkCore.Tools": { "Microsoft.EntityFrameworkCore.Tools": "1.0.0-preview2-final"
Add-Migration |
Hello,
I don't know if i'm in the right place to ask my question, sorry if not.
I want to try some little things using EF Code migrations, so i've created a new ASP.NET 5 Console Application, using Visual Studio 2015 Preview.
I then just go to my Package Manager Console, and put
Install-Package EntityFramework -Pre
. Everything is ok, i've the right dependencies in my project.json.I write some code, adding a BlogContext with 2 little entities (Blog / Post), everything looks fine, as i just copy/paste the sample here https://github.com/aspnet/EntityFramework/wiki/Using-EF7-in-Traditional-.NET-Applications.
Finally, i want to enable migrations, so i'm back in my Package Manager Console, and put
Enable-Migrations
but this error happens :The term 'Enable-Migrations' is not recognized as the name of a cmdlet
.As this command is not indicated in the EF wiki, i proceed to directly execute the command
Add-Migration MyFirstMigration
, but same error:The term 'Add-Migration' is not recognized as the name of a cmdlet
.I've tried to reboot VS, to reboot Windows, to re-install Nuget, to reset the Nightly Builds packages source, but nothing went better...
So, i tried the exact same things using VS 2013 Update 4 and a classic Console Application, and it works fine !
But i really want to use ASP.NET 5, and the K projets style... Do someone have any idea about my problem ? Did i miss something ?
Thanks,
Jeremy
The text was updated successfully, but these errors were encountered: