luckyframework / luckyframework/avram

remove_belongs_to throws error about fk constraint

Open
#711 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

feature request
Dominant language
Crystal
Stars
183
Forks
67
PR merge metrics
No merged PRs in 30d

Description

When you want to remove a belongs_to, postgres will throw an error like:

> cannot drop column whatever because other objects depend on it

This is due to the foreign constraint keys. I think when we add `remove_belongs_to`, we need to also run something like:

```crystal
execute <<-SQL
ALTER TABLE things
DROP CONSTRAINT things_whatever_id_fkey
SQL
```

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating the remove_belongs_to migration entry point and reproduce the failure against PostgreSQL with a belongs_to foreign key. Confirm that removing the association also removes the foreign-key constraint and no longer raises the reported dependency error.

Written by the indexing model from the issue text.

Assessment

Tech stack
crystal, postgresql
Domain
database
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.