#31111 closed Bug (wontfix)
Schema Editor's add_field not able to add foreign key field
| Reported by: | Akash Agrawal | Owned by: | nobody |
|---|---|---|---|
| Component: | Database layer (models, ORM) | Version: | dev |
| Severity: | Normal | Keywords: | |
| Cc: | Triage Stage: | Unreviewed | |
| Has patch: | no | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
When I try to add a foreign key field with the "to" parameter as a string instead of the model object, it is not able to create the field and instead throws a ValueError saying that it was unable to resolve the related model.
Change History (3)
comment:1 by , 6 years ago
| Resolution: | → wontfix |
|---|---|
| Status: | new → closed |
| Version: | 2.2 → master |
comment:2 by , 6 years ago
Oh! Actually I was working on a feature where i could add a foreign key dynamically using Schema Editor. I assumed it would provide all the features of Django ORM for the field. Can this is be documented in Schema Editor documentation? Shall i create a new issue for the same?
comment:3 by , 6 years ago
Can this is be documented in Schema Editor documentation?
I see no reason to document that. We cannot document the entire django.db.migrations's logic in the SchemaEditor docs.
Yes that how it works you need to provide a model.
django.db.migrationscontains the login for calculating and storing what operations should be run.SchemaEditoris the database abstraction layer that turns things like “create a model” or “delete a field” into SQL. You shouldn't interact directly with SchemaEditor as a normal developer using Django.