Opened 4 years ago

Closed 4 years ago

Last modified 4 years ago

#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


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 Mariusz Felisiak, 4 years ago

Resolution: wontfix
Status: newclosed
Version: 2.2master

Yes that how it works you need to provide a model. django.db.migrations contains the login for calculating and storing what operations should be run. SchemaEditor is 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.

comment:2 by Akash Agrawal, 4 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 Mariusz Felisiak, 4 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.

Note: See TracTickets for help on using tickets.
Back to Top