Forced default value
See original GitHub issueI create a model with a fild:
class Map(Model):
size = IntegerField()
It is NOT NULL and don’t have DEFAULT value by default:
pw.IntegerField(
null=False,
default=None,
...
)
But when I create new object, with no “size” argument put in automatically generated constructor, a model is created with a value of 0 in the size field, instead of throwing an exception.
Map.create()
/home/bukinpk/.local/lib/python3.7/site-packages/pymysql/cursors.py:170: Warning: (1364, "Field 'size' doesn't have a default value")
result = self._query(query)
Out[12]: <Map: 5>
How can I deactivate this implicit behavior?
Issue Analytics
- State:
- Created 4 years ago
- Comments:7 (3 by maintainers)
Top Results From Across the Web
Force default value when adding column to table - SQL Server
Is it possible to force the default value to be written to already existing rows when adding a new column to a table...
Read more >Forcing default values on a nullable columns
Suppose our code needs to insert the date of birth if it's supplied but should use the default value if it's not supplied,...
Read more >Force default value on existing posts - ACF Support
I have posts. I am creating a new field with a default value. It won't take it unless I create a new post....
Read more >What It Means, What Happens When You Default, Examples
A default happens when a borrower fails to make required payments on a debt, whether of interest or principal.
Read more >field calculator - QGIS 3.14: default value - GIS Stack Exchange
In QGIS' documentation on form default values, it states: The Default value option is not aware of the values in any other field...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Yes, it works! Thanks for the help!
UPD.: But it will broke some string methods, such as: https://github.com/coleifer/peewee/blob/83873b70bcdfb82320f5d3a127e4783c04531b3a/peewee.py#L4563 Becouse you use
||
as concatination operator. And if I changesql_mode
field, toSTRICT_TRANS_TABLES
, i will turn off actualy setted mode: https://github.com/coleifer/peewee/blob/83873b70bcdfb82320f5d3a127e4783c04531b3a/peewee.py#L3838 And operator||
will not work correctly. I think, I should setPIPES_AS_CONCAT,STRICT_TRANS_TABLES
Or to appendPIPES_AS_CONCAT
mode to all default setted values:STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
.Looks like this has to do with the sql_mode setting. If you change it to strict_trans_tables or strict_all_tables it should take care of the problem.