question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Forced default value

See original GitHub issue

I 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:closed
  • Created 4 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
BukinPKcommented, Oct 8, 2019

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 change sql_mode field, to STRICT_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 set PIPES_AS_CONCAT,STRICT_TRANS_TABLES Or to append PIPES_AS_CONCAT mode to all default setted values: STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION.

1reaction
coleifercommented, Oct 7, 2019

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found