emmett-framework / emmett

The web framework for inventors
BSD 3-Clause "New" or "Revised" License
1.06k stars 71 forks source link

Migrations unique argument not working #246

Closed bronte2k7 closed 2 years ago

bronte2k7 commented 5 years ago

model

class User(Model):
    auto_validation = False

    email = Field.string(
        unique=True
    )

migration generated


    def up(self):
        self.create_table(
            'users',
            migrations.Column('id', 'id'),
            migrations.Column('email', 'string', length=512),

weppy 1.3.1 Python 3.6.7

gi0baro commented 5 years ago

@bronte2k7 yep, that's a missing feature of the migrations system, it applies unique constraint only on foreign keys automatically.

you can solve it quickly in the meantime defining it in the indexes:

class User(Model):
    auto_validation = False

    email = Field.string(
        unique=True
    )

    indexes = {
        'email_unique': {'fields': ['email'], 'unique': True}
    }