-2

I've been trying to use peewee orm to insert values to db for my project, problem is that it inserts a blank value for one of the columns for seemingly no reason, I have a for loop inserting these values and it only ignores the url value, heres my model:

class RawUrl(BaseModel):

    class Meta:
        table_name = "raw_urls"
        collation = "utf8mb4_unicode_ci"
    
    url      = pw.CharField(max_length=255, null=False)
    source   = pw.ForeignKeyField(Source, backref="url_source")
    added_on = pw.DateTimeField(default=datetime.now)

I tried using get_or_create, .create, even just assigning the object to a variable and saving it but it always makes the url field blank for some reason. I am using MySQL 5.7 on ubuntu 20.04 as by database

neophyte88_
  • 1
  • 1
  • 2

1 Answers1

0

Works fine:

db = MySQLDatabase('peewee_test')

class RawUrl(db.Model):

    class Meta:
        table_name = "raw_urls"
        collation = "utf8mb4_unicode_ci"

    url      = CharField(max_length=255, null=False)
    added_on = DateTimeField(default=datetime.now)

db.create_tables([RawUrl])

RawUrl.create(url='https://example.com')
r = RawUrl.get()
print(r.url)

db.drop_tables([RawUrl])

Prints:

https://example.com
coleifer
  • 24,887
  • 6
  • 60
  • 75