Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error on migration #4

Closed
Slavenin opened this issue Jun 1, 2018 · 1 comment
Closed

Error on migration #4

Slavenin opened this issue Jun 1, 2018 · 1 comment

Comments

@Slavenin
Copy link

Slavenin commented Jun 1, 2018

Hi!
My schema:

defmodule Sandbox.Api.Request do
  use Ecto.Schema
  import Ecto.Changeset


  schema "requests" do
    field :useragent, :string
    field :ip, EctoFields.IP
    timestamps()
  end

  @doc false
  def changeset(request, attrs) do
    request
    |> cast(attrs, [:useragent, :ip])
    |> validate_required([:useragent, :ip])
  end
end

Migration:

defmodule Sandbox.Repo.Migrations.CreateRequests do
  use Ecto.Migration

  def change do
    create table(:requests) do
      add :useragent, :text
      add :ip, EctoFields.IP
      timestamps()
    end

  end
end

But on mix ecto migrate

info] == Running Sandbox.Repo.Migrations.CreateRequests.change/0 forward
** (ArgumentError) EctoFields.IP is not a valid database type, please use an atom like :string, :text and so on
    (ecto) lib/ecto/migration.ex:892: Ecto.Migration.validate_type!/1
    (ecto) lib/ecto/migration.ex:687: Ecto.Migration.add/3
    priv/repo/migrations/20180601072733_create_requests.exs:7: Sandbox.Repo.Migrations.CreateRequests.change/0
    (stdlib) timer.erl:197: :timer.tc/3
    (ecto) lib/ecto/migration/runner.ex:25: Ecto.Migration.Runner.run/6
    (ecto) lib/ecto/migrator.ex:128: Ecto.Migrator.attempt/6
    (ecto) lib/ecto/migrator.ex:73: anonymous fn/4 in Ecto.Migrator.do_up/4
    (ecto) lib/ecto/adapters/sql.ex:576: anonymous fn/3 in Ecto.Adapters.SQL.do_transaction/3
    (db_connection) lib/db_connection.ex:1283: DBConnection.transaction_run/4
    (db_connection) lib/db_connection.ex:1207: DBConnection.run_begin/3
    (db_connection) lib/db_connection.ex:798: DBConnection.transaction/3
    (ecto) lib/ecto/migrator.ex:261: anonymous fn/4 in Ecto.Migrator.migrate/4
    (elixir) lib/enum.ex:1294: Enum."-map/2-lists^map/1-0-"/2
    (ecto) lib/mix/tasks/ecto.migrate.ex:83: anonymous fn/4 in Mix.Tasks.Ecto.Migrate.run/2
    (elixir) lib/enum.ex:737: Enum."-each/2-lists^foreach/1-0-"/2
    (elixir) lib/enum.ex:737: Enum.each/2
    (mix) lib/mix/task.ex:314: Mix.Task.run_task/3
    (mix) lib/mix/cli.ex:80: Mix.CLI.run_task/2

@jerel
Copy link
Owner

jerel commented Jun 1, 2018

Good day, your schema looks correct but the migration should instead set the column type to the database type such as string or text. If you still have trouble let me know.

@jerel jerel closed this as completed Jun 1, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants