-
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
EF bundle seems to not be properly passing --connection parameter #27325
Comments
/cc @bricelam I think this is by-design, but let's discuss in triage. |
By design that it's tying into my startup project? I'm not above making a throwaway project to target just when building my EFBundle, but the fact that the connection string doesn't seem to be making it in suggests to me that my only viable approach may be to copy my appsettings.json and write my connection string straight to it rather than trying to pass it by variable. |
Duplicate of #26869. @sparksterz When |
So...I'm a little unclear as to the direction here. If I have a null connection string in startup, due to attempting to run the efbundle, are you suggesting that I don't attempt to register the context? Not knowing what the efbundle does in order to run the migrations I'm not sure if that's what you're recommending, or if you're saying I should follow the workflow in the linked bug and create an appsettings.json on the fly |
I'm suggesting you register it with either no connection string or a dummy one, since it's going to be replaced anyway. |
Yeah...that sure solved it for anyone else looking. Thanks for the help |
@ajcvickers Hi I'm also encountering this issue. It is unclear to me what I need to do in order to execute the executable when passing the connection string. What variable is it looking for in the app settings file? Also how do I copy the app settings file into the bundle? Appreciate the help! Would love to see documentation around these issues exist in documentation somewhere! |
@colespencer1453 Its taking the connection string from wherever your code takes it from. EF doesn't know anything about specific configuration files or mechanisms. To find out what this is, look for the code calling |
@ajcvickers I get the following output when running the below. When building the migration bundle I get the warning "Don't forget to copy appsettings.json alongside your bundle if you need it to apply migrations.". However, it isn't clear how to do that. My Program.cs file uses useNpgsql: The appsettings files have this variable declared. I'm unclear what else I need to add to avoid the below error. ./efbundle --connection '{connectionString}' |
@ajcvickers I eventually figured this one out. We have multiple projects with our migrations in one and startup host in the other. The appsettings file was in startup file, but I was running the efbundle executable from the migrations project. My take away here is still that the documentation is very unclear on how to use migrations bundles especially in a CI/CD context. My suggestion would be to change the warning: "Don't forget to copy appsettings.json alongside your bundle if you need it to apply migrations." output when creating a bundle to --> "Warning efbundle executable must be run in a directory with an appsettings.json file. Otherwise execution will fail." Are you all still planning to not require the appsettings file to be present? Seems very strange to require a placeholder in appsettings when you are passing the connection string as an arguement. |
@colespencer1453 could you please advise on how you made it work ? I also have multiple projects with the migrations in one and startup host in the other. |
@George2321 I wrote a small medium article about setting up migrations in an azure devops pipeline here: The command to run the migration with split proejcts looks like
This has been working pretty well for me so far. |
Thank you @colespencer1453, excellent article and work. I share your sentiment on there being a lack of documentation and it being impractical with the extra scripting and permissions required. I decided to go with the older method of using the ef core migrations script tool for now. |
For anyone following @colespencer1453's guide, just a note that when running the bundle you need to |
Thanks for your article, this is really helpful. However I am not able to execute the bundle myself in this way. I think it is because my Connection String is not of the correct format. |
I'm seeing an unusual issue when trying to create a self contained EF Bundle (6.0.1) as part of my CI script. I'm using Bitbucket pipelines for this and generating a bundle against an empty PSQL server which is successful. Once I generate the bundles I'm attempting a sanity check to run all the migrations against this empty database and that's where I'm running into issues.
Here's how I'm effectively creating trying to test the bundle via my sh script
This seems to succeed in bundle generation but not in executing the bundle against my test DB. Despite being a self contained bundle it seems that it's trying to use my application startup and my startup is failing to resolve the connection string for my server (I'll paste the full stack trace with verbose build at the end):
The code in my startup class I believe it's failing on is:
Below is my build's stack trace:
EF Core version: 6.0.1
dotnet-ef version: 6.0.1
Database provider :Npgsql.EntityFrameworkCore.PostgreSQL:6.0.2+854d2438884c0bf3a4ba8ccde2c47f7ba1ea3a4c
Target framework: .Net 6
.Net Build image: mcr.microsoft.com/dotnet/sdk:6.0
The text was updated successfully, but these errors were encountered: