简体   繁体   English

使用Peewee在MariaDB中强制执行非空字段

[英]Enforce Not Null field in MariaDB using Peewee

Well, I'm trying to use Peewee for a small project. 好吧,我正在尝试将Peewee用于一个小项目。 I need fields text and url (both longtext in MariaDB) to be not null and for not null I understand not to allow a null value to be stored in the field , so I did this: 我需要字段texturl (在MariaDB中都是longtextnot null ,对于not null我理解不允许在字段中存储null值 ,所以我这样做:

database = MySQLDatabase("mydatabase", user="", password="123justkidding", host="localhost")

class MyTable(Model):
    text = TextField(null = False)
    url = TextField(null = False, max_length = 100)

    class Meta:
        database = database

and then, of course, I created the table and I started adding values, lots of values. 然后,当然,我创建了表,并开始添加值,很多值。 The thing is that there are some empty values on text and url fields which I don't want them to be. 关键是texturl字段上有一些empty值,我不希望这样。 I ran this query: 我跑了这个查询:

SELECT `table`.`text`, `table`.`url` FROM `table` WHERE `table`.`text`="" AND `table`.`url`=""

and gave me four rows. 给了我四排 So, What am I missing guys? 那么,我在想什么呢?

Also, I notice that MariaDB has Text , Medium Text , LongText as data-types and it appears to me that TextField in Peewee is default for LongText in MariaDB . 另外,我注意到MariaDB具有TextMedium TextLongText作为数据类型,在我看来Peewee中的TextFieldMariaDB LongText默认值。 Any way I can change that? 有什么办法可以改变吗?

Thanks in advance. 提前致谢。

"" is empty string. ""为空字符串。 NULL is something different entirely. NULL完全不同。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM