简体   繁体   中英

How to change connection string on command line to update database on migration to a new database in Entity Framework Core

In ASP.NET Core and EF Core Code First, I have a multi-tenant webapp. When I create a new tenant, I want to change connection string, add migration on it and then update.

From command line, add migration can't get connection string dinamically on tenant and so i haven't a valid connection string for create a new database in the first time the app starts with a new tenant. Is there any solution for it? Thanks

Are you looking for this? Edit : this is for EF 6.1

Update-Database –ConnectionString "Data Source=YourDatabaseServer; Initial Catalog=YourDatabase; Integrated Security=True;"

I solved by inserting inside the DbContext constructor:

Database.EnsureCreated();

Thanks for your reply.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM