2trc

2trc

Mix ecto.gen.migration creates empty migration

Hi guys, so I’m following tutorials in the book “Programming Phoenix ≥ 1.4” (yes, I got the latest version cause the older one was just too hard to follow).

Under chapter 4 “Ecto and Changesets” everything works fine until I issue the command mix ecto.gen.migration create_users. The migration code i.e. change function is just empty.

I checked the folders and user.ex is under the folder lib/rumbl/accounts and it looks like this

defmodule Rumbl.Accounts.User do
  use Ecto.Schema
  import Ecto.Changeset
  schema "users" do
    field :name, :string
    field :username, :string
    timestamps()
  end
end

It’s probably a newbie question but after a couple of hours trying and re-trying, I couldn’t figure out the issue.

Help!

Marked As Solved

josevalim

josevalim

Creator of Elixir

Yes, the migration is empty! Ecto doesn’t try to magically figure out the migration from the schema. That’s why the book explicitly asks why you fill this in:

defmodule Rumbl.Repo.Migrations.CreateUsers do
  use Ecto.Migration

  def change do
    create table(:users) do
     add :name, :string
     add :username, :string, null: false
     timestamps()
    end
    create unique_index(:users, [:username]) end
  end
end

You can probably find the exact snippet in the book. :slight_smile:

Also Liked

2trc

2trc

Hi @josevalim, I missed that sentence. I was actually tempted to copy/paste from the book but I honestly thought it was auto-generated. My mis-perception came from my background in Python/Django where similar commands do generate the migration code…

I’m just an Elixir newbie learning new stuff. Thanks for helping!

mfrasca

mfrasca

Hi @2trc, are you still experimenting with Elixir? I’m also used (not too much though) to Django (I come from several years on SQLAlchemy, recently moved to Django mostly because of the ease of migrations there), and I’m a bit puzzled with ecto-migrations. I’m trying to document how they work, and help people with my same background grasp the concepts. maybe you want to have a look at my work in progress pull request, and comment.

sheltont

sheltont

I hit the same question. haha, got the same answer here.

Where Next?

Popular in Questions Top

sergio
In Ruby, I can go: User.find_by(email: "foobar@email.com").update(email: "hello@email.com") How can I do something similar in Elixir? ...
New
skosch
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New
lessless
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
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
nobody
How to bind a phoenix app to a specific ip address? could not find anything about that, nowhere, unfortunately, but for me this is quite...
New
Lily
In templates/appointment/index.html.eex: <%= for appointment <- @appointments do %> <tr> <td><%= appoi...
New
pmjoe
I have a relationship of love and hate with Elixir. Lots of things are just absolutely right, but there are some things that are kind of ...
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers’ Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New

Other popular topics Top

Darmani72
If I have a post route which an argument: post /my_post_route/:my_param1, MyController.my_post_handler How would get the post params ...
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
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
vegabook
I’m brand new to Phoenix and I have stripped one of the demo applications to the bone. I just want to get an svg up on the screen. Here i...
New
freewebwithme
Using vs code and installed ElixirLS: support and debugger. And I got an error popped up on start up says Failed to run ‘elixir’ comma...
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
marick
I had some trouble figuring out how to make many-to-many associations work. Once I got it working, I wrote a blog post. Because I’m a nov...
New
jononomo
For some reason my phoenix channels are working for me in my local dev environment, but as soon as I deploy via Docker, I get a 403 error...
New

We're in Beta

About us Mission Statement