locked
How do I apply migrations to a database when I don't have command line access? RRS feed

  • Question

  • User-1158769213 posted

    I am struggling with applying database migrations to a server to which I only have FTP access. I have published the web site, then copied the files to the server by FTP. When I access the site, I get a message telling me that there are migrations that need applying, with a button to press to apply them.

    If I click the button, I get a message saying "An error occurred applying migrations, try applying them from the command line", but doesn't tell me what the errors were. As I don't have command line access to the server, I am stuck?

    What do I do? Thanks

    Monday, June 3, 2019 3:29 PM

All replies

  • User-474980206 posted

    you should implement logging support, and a way to see the log. if you can get a backup of the production database, you can restore locally, and run the migration to debug the errors.

    Monday, June 3, 2019 3:42 PM
  • User-1158769213 posted

    Hello, thanks for the reply.

    Please bear with me as I'm new to Core. How do I implement logging? I can see that in the root folder on the server there is a folder called logs, which contains files with names like stdout_20190603114927_11196.log. Is that what you meant? If so, these aren't very helpful, as all they contain is the following...

    warn: Microsoft.AspNetCore.DataProtection.Repositories.EphemeralXmlRepository[50]
    Using an in-memory repository. Keys will not be persisted to storage.
    warn: Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager[59]
    Neither user profile nor HKLM registry available. Using an ephemeral key repository. Protected data will be unavailable when application exits.
    warn: Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager[35]
    No XML encryptor configured. Key {5ca6d628-38d5-4142-85b7-0334aa10cf0e} may be persisted to storage in unencrypted form.
    Hosting environment: Production
    Content root path: D:\HostingSpaces\myaccountname\test.mydomain.com\wwwroot
    Application started. Press Ctrl+C to shut down.
    Application is shutting down...

    As for the database, this is a brand new one. I haven't managed even the first migration yet.

    Thanks again. Any further help would be appreciated.

    Monday, June 3, 2019 3:56 PM
  • User-1158769213 posted

    OK, ignore the previous reply, I realised what you meant about logging!

    However, I had another idea, and changed the connection string in Visual Studio to point to the database on the test server. When I ran the solution, it crashed on startup as it couldn't find the tables in the database, which makes sense as I hadn't managed to apply the migrations.

    I updated the database from the Package manager Console in VS, reran and it worked fine.

    So, I am still left with the question of how I am supposed to apply migrations to a remote server. Surely I'm not expected to do this manually from VS every time? What happens on a production server?

    Thanks again.

    Monday, June 3, 2019 5:11 PM
  • User475983607 posted

    So, I am still left with the question of how I am supposed to apply migrations to a remote server. Surely I'm not expected to do this manually from VS every time? What happens on a production server?

    Depends on your deployment strategy.  You can change the connection string and  run the migrations from VS or a command line as you found.  Or script the migrations then run the script via SSMS. Or apply migrations when the app starts. 

    The EF Core migration docs cover the details.

    https://docs.microsoft.com/en-us/ef/core/managing-schemas/migrations/

    Monday, June 3, 2019 6:58 PM
  • User-2054057000 posted

    Migrations can be applied if you just have the connection string of your database. You can run your migrations using Visual Studio. I have tested this by running migrations on my online site which was hosted in ASP.NET Core hosting.

    Tuesday, June 4, 2019 3:32 AM