Modify foreign key in Ecto

I’m not sure when this was added to Ecto, but at least in 2.1.6 there’s no need for raw SQL anymore. drop/1 now supports constraints (drop_if_exists/1 doesn’t though): def up do drop constraint(:videos, “videos_user_id_fkey”) alter table(:videos) do modify :user_id, references(:users, on_delete: :delete_all) end end def down do drop constraint(:videos, “videos_user_id_fkey”) alter table(:videos) do modify :user_id, … Read more

What is a changeset in phoenix elixir

From the documentation: Changesets allow filtering, casting, validation and definition of constraints when manipulating models.. There is an example of working with changesets in the introductory documentation in the Ecto module. The functions change/2 and cast/4 are the usual entry points for creating changesets, while the remaining functions are useful for manipulating them. Changesets are … Read more

Making a field unique in ecto

You want to use unique_constraint/3. This is not like Active Record because it is using the database to ensure uniqueness. Active Record would do a query for records with the same value and if any were returned then it would fail. This has a race condition where, if a value is inserted between fetching to … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)