Coder Social home page Coder Social logo

Comments (4)

gg1229505432 avatar gg1229505432 commented on May 19, 2024

The database is designed like this, if there is already a pkid, then you can only update, and the primary key index is unique

from gorm.

gg1229505432 avatar gg1229505432 commented on May 19, 2024

If you want to migrate some data, then you can remove the pkid from the code and let him insert it himself. If you have to use pkid, then you need db.update()

from gorm.

manish-kharel avatar manish-kharel commented on May 19, 2024

Not sure if you understood the issue correctly.
The problem is, gorm is auto-assigning an ID that is already used in the database. This happens if you've previously created a Record, where you assigned the ID yourself. And after, when auto-sequence value arrives to the manually inserted value, it'll still try to use the same value regardless of the fact that the record is already there giving out pkey violation

from gorm.

a631807682 avatar a631807682 commented on May 19, 2024

The problem is, gorm is auto-assigning an ID that is already used in the database.

Gorm will not auto-assigning id

This happens if you've previously created a Record, where you assigned the ID yourself.

Yes, this is the basic functionality of the database, you can specify the id. But gorm will not process the sequence additionally.

In general, Gorm will provide some easy-to-use functions, which have basically the same semantics as the database. But it won't provide magic, as this would make it very different from directly operating the database, thereby increasing the user's learning cost.

from gorm.

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.