Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Seed script causing problems #16

Open
thchia opened this issue Jan 23, 2020 · 0 comments
Open

Seed script causing problems #16

thchia opened this issue Jan 23, 2020 · 0 comments

Comments

@thchia
Copy link
Contributor

thchia commented Jan 23, 2020

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant