I was experimenting creating a new JSONField with different options and
here is what i found:
Suppose I have a migration like this
{{{
migrations.AlterField(
model_name='awsuserschedule',
name='selected_ids',
field=common.fields.JSONField(encoder=common.encoders.JSONEncoder,
null=True),
),
migrations.AlterField(
model_name='awsuserschedule',
name='tags',
field=common.fields.JSONField(default=list,
encoder=common.encoders.JSONEncoder),
),
migrations.AlterField(
model_name='userscheduleslog',
name='instance_ids',
field=common.fields.JSONField(default=list,
encoder=common.encoders.JSONEncoder, null=False),
),
}}}
When i run sqlmigrate to analyze this migration i get:
{{{
-- Alter field selected_ids on awsuserschedule
--
ALTER TABLE `aws_user_schedules` MODIFY `selected_ids` json NULL;
--
-- Alter field tags on awsuserschedule
--
--
-- Alter field instance_ids on userscheduleslog
--
}}}
So you see that when '''null is not passed''', or '''null=False''', there
is no sql query created at all. I'm using MySQL 5.7.22. Am i doing
something wrong?
Thanks
--
Ticket URL: <https://code.djangoproject.com/ticket/32435>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* cc: Ronaldo Campos (added)
--
Ticket URL: <https://code.djangoproject.com/ticket/32435#comment:1>
* status: new => closed
* resolution: => needsinfo
* component: Uncategorized => Database layer (models, ORM)
Comment:
Thanks for this report, however there is not enough details to understand
or reproduce your issue. What kind of `JSONField` did you use before? What
was the models' state before this operations? Can you provide a sample
project?
--
Ticket URL: <https://code.djangoproject.com/ticket/32435#comment:2>
Comment (by Ronaldo Campos):
I was using the jsonfield library. But, never mind i think i figured out
what i was doing wrong. It was an issue on the previous migration states
that was causing sqlmigrate to avoid doing anything. Feel free to close
the bug report.
--
Ticket URL: <https://code.djangoproject.com/ticket/32435#comment:3>
* resolution: needsinfo => invalid
Comment:
Thanks for the feedback.
--
Ticket URL: <https://code.djangoproject.com/ticket/32435#comment:4>