I was trying this command for generate a migration for many to many:
mix ecto.gen.migration create_albums_genre album_id:references:albums:unique genre_id:references:genres:unique
but I receive an error:
** (Mix) expected ecto.gen.migration to receive the migration file name, got: "create_albums_genre album_id:references:albums:unique genre_id:references:genres:unique"
I know is possible to use this references command because I used before. But for the generate not works!
Which kind of ecto commands it will be useful using this references by the mix terminal command?
I’m not a 100% sure, but I think you might be thinking of
mix phx.gen.schema. That one allows you to use things like
name:string album_id:references:albums, etc.
I always get those confused too. I find
mix help ecto.gen.migration and
mix help phx.gen.schema help me figure out what I can and cannot pass as options.
Yes. I just don’t understand why the other commands don’t have this.
It is so useful.
Thank you for reply @germsvel!
I just don’t understand why the other commands don’t have this
That’s an excellent question. I wonder if it would be a nice contribution to Ecto?
I think yes, it’s like more productive.
You create the migration thinking about what it will fill and we know this type of set is for this in other cases. I was thinking why not have the
--pk:true and as well by coomand.
Generating a schema and generating a migration are 2 very different things. When you generate a schema you know you are doing a single
create action. Migrations can be many different actions, with multiple actions in the same migration.
For instance, you could create 5 tables. Should all of them have the same reference? Or you can be altering an index. Or modifying a column name.