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

Bug report: migration datetime field not get default #210

Open
ikuun opened this issue Jan 20, 2022 · 2 comments
Open

Bug report: migration datetime field not get default #210

ikuun opened this issue Jan 20, 2022 · 2 comments

Comments

@ikuun
Copy link

ikuun commented Jan 20, 2022

Hi,
I,m define datetime field in parent model, and set datetime defualt in parent model like:
`
class MetaModel(Model):
id = AutoField(primary_key=True)
create_time = DateTimeField(default=lambda: dt.datetime.now())
update_time = DateTimeField(default=lambda: dt.datetime.now())

class Meta:
    database = db

`
and use parent model in child model like:

`
class User(MetaModel):
name = CharField()
gender = BooleanField(default=True)
mobile = CharField(null=True)

class Meta:
    table_name = "users"

`

but when generate migration file, not get default like:

`
@migrator.create_model
class User(pw.Model):
id = pw.AutoField()
create_time = pw.DateTimeField()
update_time = pw.DateTimeField()
is_delete = pw.BooleanField(constraints=[SQL("DEFAULT False")], default=False)
name = pw.CharField(max_length=255)
gender = pw.BooleanField(constraints=[SQL("DEFAULT True")], default=True)
mobile = pw.CharField(max_length=255, null=True)

    class Meta:
        table_name = "users"`

I,m use peewee=3.14.4 peewee-migrate=1.4.6

@iddxc
Copy link

iddxc commented Apr 19, 2022

modify peeww_migrate/template.txt "import datetime as dt " to "import datetime"

@vethan
Copy link

vethan commented Feb 26, 2024

Can confirm DateTimeField gets neither defaults, nor constraints!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants