cro

cro

Newbie question here, I am experienced with Django. I create a model and associated migration and run the migration to create the tables. However, if I then refactor the model significantly (add a bunch of foreign keys, change field types) the Django migration manager is pretty good about figuring out what needs to be done to bring the database in line with the model. Sometimes the best thing to do is to remove all the interim migrations and allow Django to create the initial migration fresh, but in Phoenix I started with mix phx.gen.schema. What’s the right way to “start over” for a particular schema?

Showing Posts 1 to 5

LostKobrakai

LostKobrakai

There’s nothing comparable in elixir/ecto. The biggest reason for that being that ecto does not enforce the notion of a 1:1 mapping between schemas and db tables. There can be multiple schemas per table and neither schema holding all the columns on the table. The ecto schema in your codebase is in no way a source of truth to implicitly describe the (complete) db table. DB tables and schemas can evolve completely unrelated from each other.

This is a quite different mindset I’d imagine from what I read Django’s doing.

The other part is that generators in phoenix are just “generators”. They’re neither part of ecto (the db layer) nor actually meant to be used for more than giving you a starting boilerplate. So to start over you could run the generator again, but it’ll just generate from scratch.

cro

cro OP

I agree, this represents a different approach philosophically between the two frameworks (neither good nor bad, just different).

So what would be the right approach if I decide that my first mix phx.gen.schema was a bust and I need to do it again? How do I tell Phoenix to throw out the old migrations and how do I know which files I need to delete before I try to run the schema gen again?

kokolegorille

kokolegorille

You can get help with…

$ mix help phx.gen.schema

Generates an Ecto schema and migration.

You just need to delete the schema, and the migration file.

cro

cro OP

OK :grin: that was the only permutation of help I did not try, so TIL. Thank you for responding!

dimitarvp

dimitarvp

For future reference, you can just run mix help in your project and it will show you all tasks that are relevant to it (libraries included).

— All posts loaded —

Where Next? Top

Trending in Questions Top

katta
I having some trouble figuring out if I have set myself too strict of standards for my production server. Currently I can handle 75% of r...
New
achenet
Hello, I’m trying to build a basic Phoenix web-app, and I’d like to use Tailwind. However, when I launch mix phx.server, I get an error...
New
Cxx-mlr
I’m working on a small exercise involving update_in/3, and I came up with this solution: data = %{ name: "Periodic Table", category:...
New
ChrisAmelia
I’ve got trouble wrapping my head around the order in which functions are called in this snippet (from Phoenix’s authentication): toke...
New
dillonoconnor
Is there any way to avoid the Hologram compiler running when using iex? It seems like the front-end code could potentially be disregarded...
New
thiagogsr
** (ArgumentError) expected :max_attempts to be a positive integer, got: {:@, [line: 10, column: 19], [{:max_attempts, [line: 10, column:...
New
unaware8150
Hello folks! So at work, we are seeing some situations where we have to define some “fixed” strings that are used across the codebase in...
New

Other Trending Topics Top

GenericJam
Edit: 2026 May 15 - This post is archived. Mob is alive!! Main docs: mob v0.7.11 — Documentation A bit of explanation for the slightly c...
New
mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
budgie
A little off-topic, but I feel like people here have a good head on their shoulders. I used to be quite good at making software. Was luc...
New
KristerV
Hey. Is there anyone here who creates agents in their apps? Not talking about using agents, but creating them. I’m finding it pretty diff...
New
mcass19
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews