简体   繁体   中英

I can't create Question in python manage.py shell.(Django)

in models.py i have created class Question and then i want to create Question in models.py shell i am getting an error

models.py

from django.db import models, migrations

class Question(models.Model):
    author = models.CharField(max_length = 20)
    title = models.CharField(max_length = 30)
    body = models.TextField(null = True, blank = True)
    rating = 0
    category = models.CharField(max_length = 10)

class Migration(migrations.Migration):
    initial = True
    dependencies = []

    operations = [
        migrations.CreateModel (
            name = 'question',
            fields = [
                ('id', models.AutoField(auto_created=True,
                primary_key=True, serialize=False, verbose_name='ID')),
                ('author', models.CharField(max_length=20)),
                ('title', models.CharField(max_length = 30)),
                ('body', models.TextField(null = True, blank = True)),
                ('rating', 0),
                ('category', models.CharField(max_length = 10)), 
            ],
        ),
    ]

shell

>>> from f.models import Queston
>>> first_question =  first_question = Question(author = 'testUser', title = 'some question??', body = 'hey this is question body, category = 'some_category')

 File "<console>", line 1
    first_question = Question(author = 'testUser', title = 'some question??', body = 'hey this is question body, category = 'some_category')

You have an apostrophe missing. Try this instead:

first_question = Question(author = 'testUser', title = 'some question??', body = 'hey this is question body', category = 'some_category')

If you look at the syntax highlighting in my response and yours, you can see the word 'category' is a different colour, this is an easy way to tell you've made a typo:)

Are you Python 2 or 3? If you are Python 2, do this: raw_input(' ') . If you are Python 3, do this: input(' ') .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM