I thought this would have been a previously asked question, so maybe I'm not phrasing it right.
I tried:
manage.py python3.6 dbshell
and then:
obj= Person.objects.create('Justin')
but this did not work. Thanks for any help.
You are on the right track, but when you create model instances, you should use named parameters for the fields, so for example:
obj = Person.objects.create(name='Justin')
(given of course a Person
has a name
field)
This is logical since a model can have several fields, and there is no "inherent" order.
Using positional parameters would be very risky, since a simply "reshuffle" of the fields would result in model object constructions going wrong.
dbshell
command runs the command-line client for the database, so you'd have to use SQL to create a row in your database using that. What you actually want is the shell
command. It opens a Python interpreter with Django configured, so you can work with ORM there.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With