Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

specify appsettings while adding database migration

appsettings files

  1. appsettings.json
  2. appsettings.Production.json
  3. appsettings.Test.json
  4. appsettings.Debug.json

all for specific environment but first for common settings.

appsettings.json file does not contain connection string, since each environment has its own db.

running add-migration mig-1 obviously complains that

Could not find a connection string named 'ConnectionString'.

How can i specify connection string to be taken from appsettings.Test.json instead of default one (appsettings.json)

like image 814
tchelidze Avatar asked Mar 29 '26 20:03

tchelidze


1 Answers

Found answer in docs

add-migration mig-1 -e Test    

Note

EF Core 1.x CLI tools supported an argument called environment which could be use to specify the environment when the commands were run against an ASP.NET Core application. This argument is no longer available in 2.0:

-e|--environment <NAME>  The environment to use. Defaults to "Development".

With 2.0, you can use the ASPNETCORE_ENVIRONMENT environment variable instead.

like image 127
tchelidze Avatar answered Mar 31 '26 11:03

tchelidze