#23296 closed Bug (fixed)
Invalid parameter to create() in RunPython example
Reported by: | Areski Belaid | Owned by: | Areski Belaid |
---|---|---|---|
Component: | Documentation | Version: | 1.7-rc-2 |
Severity: | Normal | Keywords: | migrations |
Cc: | Areski Belaid, cmawebsite@… | Triage Stage: | Ready for checkin |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Following RunPython documentation: https://docs.djangoproject.com/en/dev/ref/migration-operations/#runpython
I noticed that I could not get the example running if I use argument using=db_alias.
It raises the following error:
File "../../django/django/db/models/base.py", line 457, in Model.__init__ self = <ComplexModel: ComplexModel object> *args = () **kwargs = {'using': 'default'} 455 pass 456 if kwargs: --> 457 raise TypeError("'%s' is an invalid keyword argument for this function" % list(kwargs)[0]) args_len = 0 field = <django.db.models.fields.CharField: name> fields_iter = <listiterator object at 0x2ab5a50> is_related_object = False prop = 'using' val = u'name1' 458 super(Model, self).__init__() 459 signals.post_init.send(sender=self.__class__, instance=self) TypeError: 'using' is an invalid keyword argument for this function
Nevertheless if I remove using=db_alias it works fine, replacing:
db_alias = schema_editor.connection.alias Country.objects.create(name="USA", code="us", using=db_alias) Country.objects.create(name="France", code="fr", using=db_alias)
by:
Country.objects.create(name="USA", code="us") Country.objects.create(name="France", code="fr")
Is this a bug or an error in the documentation?
Change History (6)
comment:1 by , 10 years ago
Cc: | added |
---|---|
Component: | Migrations → Documentation |
Triage Stage: | Unreviewed → Accepted |
Version: | master → 1.7-rc-2 |
comment:2 by , 10 years ago
Summary: | RunPython → Invalid parameter to create() in RunPython example |
---|
If we are showing best practices, how about using .using(db_alias).bulk_create(...)
?
comment:3 by , 10 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
+1 for best practices!
Here a PR if we are happy with this change
comment:5 by , 10 years ago
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
Note:
See TracTickets
for help on using tickets.
I think that's a problem with the docs. I don't think
create()
acceptsusing
.Maybe should we say?
Country(name="USA", code="us").save(using=db_alias)
This syntax may also work:
Country.objects.using(db_alias).create(name="USA", code="us")