question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Migration fails because the enum needs at least one row, but my data has rows?

See original GitHub issue

I’m trying to migrate data from Heroku to Docker, following the guide from here https://docs.hasura.io/1.0/graphql/manual/migrations/existing-database.html.

This is what I get when I run hasura migrate apply --endpoint http://localhost:8080: FATA[0002] apply failed: [constraint-violation] the table "frequency" cannot be used as an enum because the table must have at least one row ($.args[2].args.tables[4])

Additional information:

  1. The table frequency doesn’t have zero rows, it actually has 10 rows, at least that’s what I see on the original Heroku db that I ran hasura migrate create from.
  2. frequency isn’t the only enum table, nor was it the first one that was created. I had another enum called archive_types and this was created first and is alphabetically earlier than frequency. This enum table also has values, but the console error doesn’t seem to mention it. Why would Hasura complain that that is something wrong with frequency but not with archive_types?
  3. The only thing I did past hasura migrate create "init" was just create a test table, as stated in the guide.

Also I checked the files generated by the hasura migrate create "init" command, and it only seems to contain data about the whole Graphql/postgres schema itself (both the yaml and sql file). It doesn’t even contain a single actual row, i.e. my test data. Is there a way to migrate the data themselves too? It seems like migration isn’t that useful if it can’t do this.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:17 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
coco98commented, Oct 15, 2019

@joshuarobs This should work (while we fix this with something better):

  1. hasura migrate create "init" --from-server
  2. pg_dump <postgres-url> --column-inserts --data-only -t frequency -t archive_types >> 15xxxx_init.sql
  3. hasura migrate apply --endpoint prod-endpoint.com

You can add multiple -t flags for all the enum tables. Hope this helps!

2reactions
deathemperorcommented, Oct 9, 2020

this really needs a fix. It’s troublesome if you create the migration after making the enum tables or when refreshing the migration from scratch.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Altering an Enum field using Alembic - python - Stack Overflow
This migration will move data from one column to two others based on the type # for a given row, and modify the...
Read more >
Postgres: Enum type fields | Hasura GraphQL Docs
Enums and migrations ​. As enum tables have a requirement to contain at least 1 row, it is necessary to have a migration...
Read more >
Enum Types in Postgres - The Gnar Company
Integrating Postgres and Active Record Enums​​ Once we have run the migrations, we can replace the array in Postgres with a hash where...
Read more >
Storing Enums In a Database - Navicat
Validating Enum Values In the Database. Many modern databases, including MySQL and SQL Server, support the ENUM data type. Specified as strings, ...
Read more >
Ruby on Rails - How to Create Perfect Enum in 5 Steps
Adding enum to an existing model is a really simple task. First of all, you need to create an appropriate migration. Notice that...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found