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

Using None as a default value on mysql #23

Open
sobolevn opened this issue Sep 29, 2020 · 1 comment
Open

Using None as a default value on mysql #23

sobolevn opened this issue Sep 29, 2020 · 1 comment

Comments

@sobolevn
Copy link

Hi! Thanks a lot for this library. I am trying to use it like this:

AddDefaultValue(
            model_name='mymodel',
            name='weight',
            value=None,
        ),

And this happens:

.venv/lib/python3.7/site-packages/MySQLdb/connections.py", line 280, in query
    _mysql.connection.query(self, query)
django.db.utils.OperationalError: (1067, "Invalid default value for 'weight'")

It is unclear from the docs how to use None

@David-Wobrock
Copy link
Contributor

Hi @sobolevn
Thanks for submitting an issue :)

I do not think that it is necessary to have a AddDefaultValue operation for a default NULL value.
On MySQL, a Python None is a SQL NULL.

Either the weight column is nullable, and the default value will be NULL by convention (when not specifying the value in an INSERT => is null by default, or Django will define it in an INSERT => Django will put a null) => you don't need a AddDefaultValue
Or the column is NOT NULL, in which case the default value cannot be NULL anyway

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