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

create_tables() does not create any fields #2912

Closed
PhilippCh opened this issue Jul 8, 2024 · 2 comments
Closed

create_tables() does not create any fields #2912

PhilippCh opened this issue Jul 8, 2024 · 2 comments

Comments

@PhilippCh
Copy link

Hi there!

New to python in general, so please excuse it if I'm doing something wrong, but I cannot figure out why create_tables([Task]) does not create the fields that I provided for the Task class.

import datetime

from peewee import Model, TextField, BooleanField, DateTimeField
from playhouse.shortcuts import model_to_dict
from playhouse.sqlite_ext import SqliteExtDatabase

db = SqliteExtDatabase('shoppr.db', pragmas={
    'journal_mode': 'wal',  # WAL-mode.
    'cache_size': -64 * 1000,  # 64MB cache.
    'synchronous': 0})


class Task(Model):
    title: TextField()
    description: TextField()
    createdAt = DateTimeField(default=datetime.datetime.now)
    changedAt = DateTimeField(default=datetime.datetime.now)
    isDone: BooleanField(default=False)

    class Meta:
        database = db


db.connect()
db.create_tables([Task])

All that is created from this in the SQLite db is the id column:
image

When debugging into create_tables(), it appears that the model is missing some fields (title, description, isDone) while others (createdAt, changedAt) are present, but not created in the DB.
image

Is there anything I'm doing wrong? Your help would be greatly appreciated!

@Seluj78
Copy link

Seluj78 commented Jul 8, 2024

You are using : instead of = :)

Try

import datetime

from peewee import Model, TextField, BooleanField, DateTimeField
from playhouse.shortcuts import model_to_dict
from playhouse.sqlite_ext import SqliteExtDatabase

db = SqliteExtDatabase('shoppr.db', pragmas={
    'journal_mode': 'wal',  # WAL-mode.
    'cache_size': -64 * 1000,  # 64MB cache.
    'synchronous': 0})


class Task(Model):
    title = TextField()
    description = TextField()
    createdAt = DateTimeField(default=datetime.datetime.now)
    changedAt = DateTimeField(default=datetime.datetime.now)
    isDone = BooleanField(default=False)

    class Meta:
        database = db


db.connect()
db.create_tables([Task])

This gives me
Screenshot 2024-07-08 at 12 22 21

@PhilippCh
Copy link
Author

Oh wow, thanks a lot... like I said, still getting used to python 😀

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

2 participants