8000 Seed script causing problems · Issue #16 · TechLadies/reach-backend · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
Seed script causing problems #16
Open
@thchia

Description

@thchia

Observed

Creating a Donation record in the database via Sequelize fails with the following error:

ERROR: duplicate key value violates unique constraint <"xxx_pkey">
DETAIL: Key (id)=(15) already exists.

Cause

Turns out this only happens when there is already data in the DB that was put there via the seed script (npm run db:seed). This comment suggests that including the primary key attribute in the seed data is unadvisable.

Solution

The seed data needs to be updated to remove the IDs from Donations and Donors. However, the seeded Donation records still should have a donorId that corresponds to a Donor primary key. So

  1. Donors need to be inserted first;
  2. We need some way to get the list of Donor IDs and randomly (?) assign them to the Donations to be seeded.

In the interim, the DB should be reset and the seed script not used. The /donations/upload endpoint can be used to insert data.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0