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

Sqlite Custom field Changes Primary Key error #880

Closed
galizhan opened this issue May 15, 2021 · 1 comment
Closed

Sqlite Custom field Changes Primary Key error #880

galizhan opened this issue May 15, 2021 · 1 comment
Assignees
Labels
type: bug 🐛 Something isn't working

Comments

@galizhan
Copy link

**Sqlite Custom field Changes Primary Key error **
When adding custom fields, and we have already added data to database(demo data), It causes SqliteError: FOREIGN KEY constraint failed error

To Reproduce
Steps to reproduce the behavior:

  1. Go to 'vendure-config.ts'
  2. Add 'customFields'
  3. Generate migrations
  4. Run migrations

Expected behavior
Changes have to migrated to db.

Environment (please complete the following information):

  • @vendure/core version:1.0.0-rc.0
  • Nodejs version: 12.0
  • Database (mysql/postgres etc): sqlite3

Temporary fix
I know that disableForeignKeysForSqLite function but it seems like doesn't work for this situation, so if you similar problem you can make it like this.

  1. Go to 'node_modules/@vendure/core/migrate.js'
  2. Find function runMigrations
  3. Before try paste this code await connection.query('PRAGMA foreign_keys=OFF');
  4. At the end of paste this code await connection.query('PRAGMA foreign_keys=ON');
@galizhan galizhan added the type: bug 🐛 Something isn't working label May 15, 2021
@michaelbromley
Copy link
Member

Ah ok I think I know what is going on here: the disableForeignKeysForSqLite function is only checking for the sqlite driver, but since then we moved over to use the better-sqlite3 driver by default, which would cause the check to fail.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug 🐛 Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants