0

hi i m new to django and made a biodata form but the problem is that when i try to save the form to the db it gives the error- (1146, "Table 'django_db.tictactoe_biodata' doesn't exist")

any help is appreciated..:)

my views.py

from django.shortcuts import render
from model import BiodataForm, Biodata

def get_name(request):
    if request.method == 'POST':
        post = request.POST
        form = BiodataForm(request.POST)
        if form.is_valid():
            biodata = form.save()
            firstname = post['first_name']
            lastname = post['last_name']
            return render(request, 'now.html', {'firstname': firstname, 'lastname': lastname})
    else:
        form = BiodataForm()
    return render(request, 'name.html', {'form': form})

my settings.py

DATABASES = {
    'default': {
    'ENGINE': 'django.db.backends.mysql',
    'NAME': 'django_db',
'PASSWORD': 'password',
'USER': 'djangouser',
'HOST': '',
'PORT': ''
}

}

and the errors-

>ProgrammingError at /getname/

>(1146, "Table 'django_db.tictactoe_biodata' doesn't exist")

>Request Method:    POST
>Request URL:   http://10.8.21.17:3369/getname/
>Django Version:    1.6.1
>Exception Type:    ProgrammingError
>Exception Value:   

>(1146, "Table 'django_db.tictactoe_biodata' doesn't exist")

>Exception Location:    /usr/lib/python2.7/dist-packages/MySQLdb/connections.py in         >defaulterrorhandler, line 36
>Python Executable:     /usr/bin/python
>Python Version:    2.7.6
>Python Path:   

>['/home/aquaman/tictactoe',
> '/usr/lib/python2.7',
 >'/usr/lib/python2.7/plat-x86_64-linux-gnu',
> '/usr/lib/python2.7/lib-tk',
> '/usr/lib/python2.7/lib-old',
> '/usr/lib/python2.7/lib-dynload',
> '/usr/local/lib/python2.7/dist-packages',
> '/usr/lib/python2.7/dist-packages',
> '/usr/lib/python2.7/dist-packages/PILcompat',
 >'/usr/lib/python2.7/dist-packages/gtk-2.0',
>'/usr/lib/python2.7/dist-packages/ubuntu-sso-client']

>Server time:   Wed, 7 Jan 2015 10:25:26 +0000

i m using my college provided proxified net i dont know if the problem is ip address or anything else

thanks in advance

2
  • 1
    Why would it have anything to do with IP addresses? The error message is quite clear, the db table doesn't exist. Have you created migrations and run them? Commented Jan 7, 2015 at 10:51
  • @DanielRoseman he is using django 1.6 so there's no builtin support for migrations. Commented Jan 7, 2015 at 11:09

2 Answers 2

1

The error message seems quite clear: you have defined a model in django but forgot to create the model's table in your database. In django < 1.7, the builtin management command syncdb (https://docs.djangoproject.com/en/1.6/ref/django-admin/#syncdb) will create the table if it doesn't exist, but you'll have to manually take care of schema changes (if you add / remove / modify fields from an existing model), so I strongly advise you either use South (https://south.readthedocs.org/en/latest/) to handle schema and data migrations or just upgrade to django 1.7 which has builtin support for schema and data migrations.

As a side note: the good practice after a successfull post is to redirect (http://en.wikipedia.org/wiki/Post/Redirect/Get).

Sign up to request clarification or add additional context in comments.

1 Comment

thnx for d help sir...i will try this for sure..:)
0

You have to create migrations and run them. I see that you are using Django 1.6.1 so you have to follow these steps:

Open your settings.py and check if you have 'south' on your INSTALLED_APPS (If not, follow this guide)

Open the terminal

Go to the root of your project (where there is a file called manage.py)

Run the following commands:

python manage.py syncdb
python manage.py schemamigration nameofyourapp --initial
python manage.py migrate nameofyourapp
python manage.py schemamigration nameofyourapp --auto

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.