Cam
Add reference to existing column
Here is my original migration:
def change do
create table(:clipboard_items) do
add(:clipboard_id, :integer)
timestamps()
end
end
During this migration, I forgot to add the reference for each of these fields. It should have looked like this:
def change do
create table(:clipboard_items) do
add(:clipboard_id, references(:clipboards))
timestamps()
end
end
How can I add the reference to the existing table?
I’ve tried this:
def change do
alter table(:clipboard_items) do
modify :clipboard_id, references(:clipboards)
end
end
But I get this error:
alter table clipboard_items
** (Postgrex.Error) ERROR 42710 (duplicate_object) constraint "clipboard_items_clipboard_id_fkey" for relation "clipboard_items" already exists
I’m not able to rollback because that migration has already run on production
This is making so I can’t cascade delete, any help on this would be great!
Most Liked
Cam
Turns out this will work:
defmodule Dreamhouse.Repo.Migrations.AddReferenceToClipboardItem do
use Ecto.Migration
def up do
execute "ALTER TABLE clipboard_items DROP CONSTRAINT clipboard_items_clipboard_id_fkey"
alter table(:clipboard_items) do
modify :clipboard_id, references(:clipboards, on_delete: :delete_all)
end
end
def down do
execute "ALTER TABLE clipboard_items DROP CONSTRAINT clipboard_items_clipboard_id_fkey"
alter table(:clipboard_items) do
modify :clipboard_id, references(:clipboards, on_delete: :nothing)
end
end
end
VIA: Github Issue
2
Popular in Questions
After calling mix ecto.create I get this error:
17:00:32.162 [error] GenServer #PID<0.412.0> terminating
** (Postgrex.Error) FATAL...
New
Could someone help me? I’m making my first elixir program, number guessing game. I can’t figure out how to convert the user’s guess from ...
New
Hello, I get Persian date from my client and convert it to normal calendar like this:
def jalali_string_to_miladi_english_number(persi...
New
I am trying to implement my new.html.eex file to create new posts on my website.
new.html.eex:
<h1>Create Post</h1>
<%= ...
New
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
I have VueJS GUIs with the project generated using Webpack.
I have Elixir modules that will need to be used by the VueJS GUIs.
I forese...
New
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this:
...
New
I have a super simple question about elixir - how would I take a file like this
foo
bar
baz
and output a new file that enumerates th...
New
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
Hello!
Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
Other popular topics
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
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service.
Currently when I de...
New
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
Surface is an experimental library built on top of Phoenix LiveView and its new LiveComponent API that aims to provide a more declarative...
New
In templates/appointment/index.html.eex:
<%= for appointment <- @appointments do %>
<tr>
<td><%= appoi...
New
i’m a new one to elixir
which editor can i use
vs code? or atom?
Thanks! :smiley:
New
Hi folks,
Few months ago I have announced the proof-of-concept of the library to manipulate the browsers DOM objects directly from Elixi...
New
There are pre-rolled solutions for other frameworks that do work. However, Phoenix does not seem to have these. Have people had good expe...
New
Seen any cool LiveView demos, sample apps or examples? Please post them here! :003:
New
Hi!
Currently I want to submit a form by pressing the Enter key. However, since my input field is of type “textarea” this is just adds a...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #javascript
- #code-sync
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance








