Giter Site home page Giter Site logo

migrate apply error when fk changed about atlas HOT 4 CLOSED

idc77 avatar idc77 commented on August 26, 2024
migrate apply error when fk changed

from atlas.

Comments (4)

masseelch avatar masseelch commented on August 26, 2024

Hey! This migration fails because of a data dependent change. You are adding a foreign key on data where that does not satisfy this constraint.

In your case the image table seems to hold a row with an recipe id that does not exist.

There are ways to fix this, e.g. by removing conflicting rows before applying the change.

I suggest you have a look at the atlas migrat lint command.

from atlas.

idc77 avatar idc77 commented on August 26, 2024

Ok but this isn't fixed.
I know what's happening, but this can still happen again anytime a field is added to the foreign key edge.

Before there was just an edge that went from recipe to image O2M.

Now the image has a named field "recipe_id", so the table had its field changed from recipe_image to recipe_id.
But the migration tool is unable to create a proper migration.

This is a bug.

Atlas is supposed to be a tool that keeps watch and helps with migrations, tracks changes and creates the SQL so that you can apply all the migrations in sequence.
In this case it doesn't do the job, it fails to do the job, creates a non-working migration.

from atlas.

giautm avatar giautm commented on August 26, 2024

Hello @idc77, you can use the StorageKey option to keep the old column, so any migration engine (ent’s or atlas) won’t try to drop and re-create the column for that field. Please let me know if it helps.

https://entgo.io/docs/schema-fields/#storage-key

from atlas.

masseelch avatar masseelch commented on August 26, 2024

I just see now that it drops and re-creates the column, sorry missed that before. It's not really possible to determine if for a change made in the desired schema if it's a rename (like in your case) or a drop+add with equal types.

This is one of the reasons why there is atlas migrate lint. It would have told you that dropping a column is dangerous and most likely not intentional. Also, you can edit a generated migration and change the drop+add to a column rename. Or just use the StorageKey option as @giautm mentioned to keep the database column name.

However, we are actively working on solutions for these type of problems.

from atlas.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.