romenigld

romenigld

Ecto generate migration with references with mix on the terminal command

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?

Marked As Solved

germsvel

germsvel

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.

Also Liked

romenigld

romenigld

Yes. I just don’t understand why the other commands don’t have this.
It is so useful.
Thank you for reply @germsvel!

joey_the_snake

joey_the_snake

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.

Last Post!

joey_the_snake

joey_the_snake

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.

Where Next?

Popular in Questions Top

RisingFromAshes
I’ve read in another post that it may be possible with a router helper - but I couldn’t find an appropriate one, and tbh, I’m still just ...
New
minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
joeerl
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New
Fl4m3Ph03n1x
About me? ( if you have nothing better to do than reading about some random guy in the internet :stuck_out_tongue: ) Hello all, this is ...
New
fireproofsocks
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? Ecto.Repo — Ecto v3.14.0 has exampl...
New
senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New

Other popular topics Top

electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New
greenz1
I have a phoenix application from which a user can download multiple(5-6) files of size 1MB. I couldn’t find anything related to sending ...
New
shijith.k
I am trying to start a new phoenix project with elixir 1.9, but mix phx.new does not work. It says that ** (Mix) The task "phx.new" could...
New
msaraiva
Surface is an experimental library built on top of Phoenix LiveView and its new LiveComponent API that aims to provide a more declarative...
564 44139 214
New
TunkShif
This post is an instruction guide to help you setup your Neovim for Elixir development from scratch. It includes general information on h...
274 42533 114
New

We're in Beta

About us Mission Statement