superset icon indicating copy to clipboard operation
superset copied to clipboard

error when use superset db migrate

Open hieuthanhpro opened this issue 1 year ago • 1 comments

Bug description

I add two collumn in model dashboard and have error

How to reproduce the bug

  1. I add two column in model dashboard: public and organizationId

class Dashboard(Model, AuditMixinNullable, ImportExportMixin): """The dashboard object!"""

__tablename__ = "dashboards"
id = Column(Integer, primary_key=True)
dashboard_title = Column(String(500))
position_json = Column(utils.MediumText())
description = Column(Text)
css = Column(Text)
certified_by = Column(Text)
certification_details = Column(Text)
json_metadata = Column(utils.MediumText())
slug = Column(String(255), unique=True)
public = Column(Boolean)
organizationId = Column(Integer)
2. I run superset db migrate -m "add-column-dashboard" 
3. have error:
    raise exc.CompileError("PostgreSQL ENUM type requires a name.")

sqlalchemy.exc.CompileError: PostgreSQL ENUM type requires a name.

Screenshots/recordings

image

Superset version

3.1.3

Python version

3.9

Node version

16

Browser

Chrome

Additional context

No response

Checklist

  • [ ] I have searched Superset docs and Slack and didn't find a solution to my problem.
  • [ ] I have searched the GitHub issue tracker and didn't find a similar bug report.
  • [ ] I have checked Superset's logs for errors and if I found a relevant Python stacktrace, I included it here as text in the "additional context" section.

hieuthanhpro avatar Jun 26 '24 09:06 hieuthanhpro

@hieuthanhpro Hello there! I'm a bot designed to help you solve bugs, answer questions, and become a contributor. I'm here to assist you while waiting for a human maintainer.

To resolve the PostgreSQL ENUM type requires a name error when running superset db migrate after adding public and organizationId columns to the dashboard model, you need to ensure that the ENUM type is given a name. In SQLAlchemy, you can specify the name of the ENUM type using the name parameter.

Here is an example of how you can define the ENUM type with a name in your model:

from sqlalchemy import Column, Integer, Enum

class Dashboard(Base):
    __tablename__ = 'dashboard'
    
    id = Column(Integer, primary_key=True)
    public = Column(Enum('private', 'public', name='public_enum'))
    organizationId = Column(Integer)

Make sure to replace 'private' and 'public' with the actual values you want in your ENUM type. The name='public_enum' part is crucial as it provides a name for the ENUM type, which is required by PostgreSQL.

After making this change, run superset db migrate again, and the error should be resolved [1].

To continue talking to Dosu, mention @dosu.

dosubot[bot] avatar Jun 26 '24 09:06 dosubot[bot]