Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for db_alias in migrations #63

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

JudgeManz
Copy link

Issue

Current migrations require that the django-raster library's tables are created at the "default" database connection in settings.py. This did not allow the library to work with multiple databases and database routers if django-raster's tables weren't being created in the "default" database connection.

Solution

Modified migrations to allow django-raster to run migrations and create the tables in a different database connection. This allows the library to support the creation of tables in a different database such as when running "python manage.py migrate --database=db_name"

Migration Changes

Migration 0005: Changed the RunSQL function to RunPython so that migrations won't run into an error when the user enters "python manage.py migrate" when django-raster's tables are being created in a database that isn't in the "default" connection.

Migrations 0017, 0022, 0034, 0036: Added "db_alias = schema_editor.connection.alias" to let the migration use the database connection specified by the user or the router. Changed "for x in ModelName.object.all()" to "for x in ModelName.objects.using(db_alias).all()" in the migration python functions to use the specified database connection.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant