5

After adding migrations in a code first approach, when i need to apply changes to production database (postgresql 13), i need to generate script for those changes.

script-migration

from microsoft docs generates sql script for SQL Server. but i need it for postgresql. there is an online tool that converts SQL server script to Postgresql but introduces errors. Is there a way to produce postgresql script automatically? As i am not very confident with postgresql syntax.

8
  • Do you have a Postgresql-Connection in your Application? Commented May 1, 2021 at 11:40
  • 1
    Look at this tutorial maybe it helps. Commented May 1, 2021 at 11:44
  • @Nikolaus yes, i have postgresql-connection using this "Npgsql Entity Framework Core Provider" and yes this tutorial is exactly what i have done. the problem is that i cannot generate migration scripts for postgresql. Commented May 2, 2021 at 13:23
  • Does it work with Update-Database? Commented May 2, 2021 at 16:46
  • If it works with Update-Database, I'd suggest to open a new issue on Github Commented May 2, 2021 at 16:57

1 Answer 1

1

Shay Rojansky from the npgsql team mentioned "The typical way is to maintain a set of migrations for each provider, and at that point you can generate SQL migration scripts for the provider you want." This link https://learn.microsoft.com/en-us/ef/core/managing-schemas/migrations/providers?tabs=dotnet-core-cli provides the details for using multiple providers. And i was missing the --project and --provider parameters when adding migrations and i needed to maintain a set of migrations for each provider. And in case you have only one provider enabled (with one db context) like this, scipt-migration command will create script for it.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.