Using a fresh install of Phoenix LiveView for the first time and onboarding is not going as expected.
Excerpt of commands on a new project with MySQL …
mix phx.new reepx --database mysql
mix phx.gen.auth Users User users
Run the migrations, build, it just works.
Now, add another table to it:
mix phx.gen.live Links Link links url:text
Generates
defmodule Reepx.Repo.Migrations.CreateLinks do
use Ecto.Migration
def change do
create table(:links) do
add :url, :text
add :user_id, references(:users, type: :id, on_delete: :delete_all)
timestamps(type: :utc_datetime)
end
create index(:links, [:user_id])
end
end
Running the migration for links gives me errors:
09:18:34.824 [info] create table links
** (MyXQL.Error) (1005) (ER_CANT_CREATE_TABLE) Can't create table `reepx_dev`.`links` (errno: 150 "Foreign key constraint is incorrectly formed")
Generated query is:
CREATE TABLE `links` (`id` bigint unsigned not null auto_increment, `url` text, `user_id` integer, CONSTRAINT `links_user_id_fkey` FOREIGN KEY (`user_id`) REFERENCES `users`(`id`) ON DELETE CASCADE, `inserted_at` datetime NOT NULL, `updated_at` datetime NOT NULL, PRIMARY KEY (`id`)) ENGINE = INNODB
Obviosuly the automatically added field user_id
in not generated as bigint unsigned
to match the users.id
.
What am I doing wrong?
Using MariaDB 11.7.2
with
{:phoenix, "~> 1.8.0"},
{:phoenix_ecto, "~> 4.5"},
{:ecto_sql, "~> 3.13"},
{:myxql, ">= 0.0.0"},