News for hackers. Stuff that matters.
Re:Notes on Starting to Use Django by hansonkd on Wednesday January 28, 2026 @12:07AM (#46791298)
Its crazy to me after all these years that django-like migrations aren't in every language. On the one hand they seem so straightforward and powerful, but there must be some underlying complexities of having it autogenerate migrations.

Its always a surprise when i went to Elixir or Rust and the migration story was more complicated and manual compared to just changing a model, generating a migration and committing.

In the pre-LLM world, I was writing ecto files, and it was super repetitive to define make large database strucutres compared to Django.

Re:Notes on Starting to Use Django by dnautics on Wednesday January 28, 2026 @12:24AM (#46791414)
well in elixir you can have two schemas for the same table, which could represent different views, for example, an admin view and a user view. this is not (necessarily) for security but it reduces the number of columns fetched in the query to only what you need for the purpose.
Re:Notes on Starting to Use Django by IceDane on Wednesday January 28, 2026 @12:54AM (#46791579)
There is no way to autogenerate migrations that work in all cases. There are lots of things out there that can generate migrations that work for most simple cases.
Re:Notes on Starting to Use Django by boxed on Wednesday January 28, 2026 @04:07AM (#46792860)
That's why you can do your own migrations in Django for those edge cases.
Re:Notes on Starting to Use Django by etchalon on Wednesday January 28, 2026 @01:17AM (#46791721)
Django manages to autogenerate migrations that work in the VAST majority of cases.
Re:Notes on Starting to Use Django by frankwiles on Wednesday January 28, 2026 @06:35AM (#46794036)
I end up needing to write a manual migration maybe once every other year in real world use.
Re:Notes on Starting to Use Django by hansonkd on Wednesday January 28, 2026 @10:17AM (#46796435)
They don't need to work in every case. For the past `~15 years 100% of the autogenerated migrations to generating tables, columns or column names I have made just work. and i have made thousands of migrations at this point.

The only thing to manually migrate are data migrations from one schema to the other.

Re:Notes on Starting to Use Django by igsomething on Wednesday January 28, 2026 @01:49AM (#46791886)
Going from Django to Phoenix I prefer manual migrations. Despite being a bit tedious and repetitive, by doing a "double pass" on the schema I often catch bugs, typos, missing indexes, etc. that I would have missed with Django. You waste a bit of time on the simple schemas, but you save a ton of time when you are defining more complex ones. I lost count on how many bugs were introduced because someone was careless with Django migrations, and it is also surprising that some Django devs don't know how to translate the migrations to the SQL equivalent.

At least you can opt-in to automated migrations in Elixir if you use Ash.

Re:Notes on Starting to Use Django by limagnolia on Wednesday January 28, 2026 @06:07PM (#46803017)
Django doesn't force anyone to use the automatic migrations, you can always write them manually if you want to :)
Re:Notes on Starting to Use Django by wiredfool on Wednesday January 28, 2026 @04:22AM (#46792989)
There are some subtle edge cases in the django migrations where doing all the migrations at once is not the same as doing migrations one by one. This has bitten me on multiple django projects.
Re:Notes on Starting to Use Django by cuu508 on Wednesday January 28, 2026 @07:11AM (#46794320)
Can you give an example how this would happen?
Re:Notes on Starting to Use Django by wiredfool on Wednesday January 28, 2026 @07:24AM (#46794421)
Ok, from memory --

There's a pre, do and post phase for the migrations. When you run a single migration, it's: pre, do, post. When you run 2 migrations, it's: pre [1,2], do: [1,2], post: [1,2].

So, if you have a migration that depends on a previous migration's post phase, then it will fail if it is run in a batch with the previous migration.

When I've run into this is with data migrations, or if you're adding/assigining permissions to groups.

Re:Notes on Starting to Use Django by brianwawok on Wednesday January 28, 2026 @08:21AM (#46795019)
There’s like an atomic flag you can pull it out of the transaction . Solves a lot of these issues.
Re:Notes on Starting to Use Django by hansonkd on Wednesday January 28, 2026 @10:20AM (#46796489)
Does that affect the autogenerated migrations at all? Teh only time I ran into that issue as if I generated a table, created a data migration and then it failed because the table was created same transaction. Never had a problem with autogenerated migrations.
Re:Notes on Starting to Use Django by advisedwang on Wednesday January 28, 2026 @04:26PM (#46801758)
What a crazy design, why don't they just do pre1 do1 post1 pre2 do2 post2?
Re:Notes on Starting to Use Django by Izkata on Wednesday January 28, 2026 @08:27PM (#46804477)
This doesn't sound at all familiar, are you sure you're not mixing it up with something else?
Re:Notes on Starting to Use Django by selcuka on Wednesday January 28, 2026 @11:58PM (#46805974)
Did you mean migration signals (pre_migrate and post_migrate)? They are only meant to run before and after the whole migration operation, regardless of how many steps are executed. They don't trigger for each individual migration operation.

The only catch is they will run multiple times, once for each app, but that can also be prevented by passing a sender (e.g. `pre_migrate.connect(pre_migrate_signal_handler, sender=self)` if you are registering them in your AppConfig.ready method).