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

Enum in migration not working (Postgres) #359

Closed
Marlysson opened this issue Feb 2, 2021 · 7 comments
Closed

Enum in migration not working (Postgres) #359

Marlysson opened this issue Feb 2, 2021 · 7 comments
Labels
bug An existing feature is not working as intended

Comments

@Marlysson
Copy link
Contributor

Describe the bug
A migration using enum type in postgres database isn't working.

To Reproduce

  1. Create a migration with table.enum('gender', ['male', 'female'])
  2. Run migration

Expected behavior
Constraint check is have to create normally.

Screenshots
image

What database are you using?
Postgres

@Marlysson Marlysson added the bug An existing feature is not working as intended label Feb 2, 2021
@josephmancuso
Copy link
Member

Actually no. This is the proper way to create enums in Postgres we can do:

CREATE TYPE users10_genders_enum AS ENUM ('male', 'female');

create table users10(
    genders users10_genders_enum
);

@josephmancuso
Copy link
Member

josephmancuso commented Feb 2, 2021

Another way all in one line and probably easier is to do this:

create table users11(
    genders VARCHAR(255) CHECK (genders = 'male' OR genders = 'female')
);

This just involves changing the male, female syntax to genders = 'male' OR genders = 'female'

@josephmancuso
Copy link
Member

josephmancuso commented Feb 2, 2021

Lastly we can also do this. This requires to smallest change:

create table users12(
    genders VARCHAR(255) CHECK (genders IN ('male', 'female'))
);

This just requires adding {column} IN to the query

@josephmancuso
Copy link
Member

postgres has so many damn ways to do this

@Marlysson
Copy link
Contributor Author

This seems the better way:

genders VARCHAR(255) CHECK (genders IN ('male', 'female'))

I have a postgres installed, I can test against a database this behavior. Or do you think define this as a good first issue issue?

@josephmancuso
Copy link
Member

no this needs to be fixed ASAP

@josephmancuso
Copy link
Member

Fixed in #363

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug An existing feature is not working as intended
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants