运行 共享主机环境中的 EF 数据库迁移

Running EF database migrations in shared hosting environment

我有一个托管在共享主机上的网站,当我尝试 运行 'update-database' 时,我得到了这个错误:

This operation requires a connection to the 'master' database. Unable to create a connection to the 'master' database because the original database connection has been opened and credentials have been removed from the connection string. Supply an unopened connection.

显然提供商不会给我访问 master 的权限。我运气不好吗?

update-database 确实需要访问 'master' 数据库才能添加新数据库。 Entity Framework 假定数据库默认不存在,并且 运行 Create Database。如果您的主机提供商只允许您访问共享实例而不是共享服务器上您自己的实例,那么没有他们的帮助您可能无法创建新的数据库。

如果您使用命令 Update-Database -Script -SourceMigration: $InitialDatabase,它将生成一个 .sql 脚本,该脚本可以 运行 针对数据库,由您的托管服务提供商或通过他们为您提供的任何门户.