Thursday, December 9, 2021

Re: Why does sqlmigrate need a connection to an existing database?

It uses db connection in two places:

building the migration graph in order to load previous applied migrations and transaction begin/end wrapping

This makes sense, because you can have N unapplied migrations between the db and your migrations history package.  

On Tuesday, December 7, 2021 at 7:46:42 PM UTC-5 wrote:
Wondering why sqlmigrate needs a connection to an existing database.

I understand that for certain commands, it needs the database to generate the migration. But for most (basic) commands, no connection is really needed.

For example, I created a test project and generated migration files. Without ever running the `migrate` command, I was able to use `sqlmigrate` perfectly well on all migrations, save the last, which drops a `unique_together`.

I'm sure there are other commands which actually need a database connection (though I haven't found them yet). Seems to me sqlmigrate could be rewritten along the lines of:
  • Try to generate sql from migration file
  • If it hits a command it needs the database, attempt to connect
Or else:
  • If no connection, check if migration file needs connection to database
Is there something I'm unaware of?

This email may contain confidential material; unintended recipients must not disseminate, use, or act upon any information in it. If you received this email in error, please contact the sender and permanently delete the email.

You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
To view this discussion on the web visit

No comments:

Post a Comment