Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Django Forms More on Models Multiple Choice and True/False Questions

Derrick Kearney
Derrick Kearney
2,962 Points

Migrate is Failing - Asking Multiple Choice django.db.utils.OperationalError: no such table: courses_step

I am working through, start to finish on the forms. When we amended Step to abstract I started getting the following error. django.db.utils.OperationalError: no such table: courses_step

I compared my code against models.py from the downloaded code, used diff at the command line and my code is identical. I thought it might be the database so I copied the existing database from the example code the first time this happened. Re ran the makemigrations and migrate, and it worked.

I thought it was solved, I was mistaken.

When I added class MultipleChoiceQuestion and ran migrate, the error appeared again. no such table: courses_step

My models. py is here https://ghostbin.com/paste/j72dx

The traceback is here: https://ghostbin.com/paste/ch6nd I am working and taking this course, so maybe I am missing something simple.

Chris Freeman
Chris Freeman
Treehouse Moderator 68,423 Points

Can you post the output of ./manage.py makemigrations courses and ./manage.py showmigrations courses. Or the output of ./manage.py makemigrations and ./manage.py showmigrations.

Derrick Kearney
Derrick Kearney
2,962 Points

Chris, ./manage.py makemigrations courses No changes detected in app 'courses'

django-admin showmigrations
https://ghostbin.com/paste/4tcgb

Chris Freeman
Chris Freeman
Treehouse Moderator 68,423 Points

django-admin doesn't have your settings defined. Please use

$ ./manage.py showmigrations --list

Derrick Kearney
Derrick Kearney
2,962 Points

here it is, ./manage.py showmigrations --list

 [X] 0001_initial  
auth  
 [X] 0001_initial  
 [X] 0002_alter_permission_name_max_length  
 [X] 0003_alter_user_email_max_length  
 [X] 0004_alter_user_username_opts  
 [X] 0005_alter_user_last_login_null  
 [X] 0006_require_contenttypes_0002  
contenttypes  
 [X] 0001_initial  
 [X] 0002_remove_content_type_name  
courses  
 [X] 0001_initial  
 [X] 0002_step  
 [X] 0003_auto_20150601_1513  
 [ ] 0004_auto_20160216_2055  
 [X] 0005_quiz  
 [ ] 0006_auto_20160217_1742  
 [X] 0007_answer  
 [ ] 0008_multiplechoicequestion  
sessions  
 [X] 0001_initial
Derrick Kearney
Derrick Kearney
2,962 Points

Chris, it fails on:

 ./manage.py migrate courses  0004_auto_20160216_2055    
OperationalError: no such table: courses_step    
Derrick Kearney
Derrick Kearney
2,962 Points

Chris, fyi, I copied a sample S2V4, and I am working off that. That said, I am perplexed as to how to resolve this, but I do not want you and I going down a rabbit hole.

Derrick Kearney
Derrick Kearney
2,962 Points

Agreed Chris, done, and resolved. Thanks. None of your answers fixed it, your comment did.

2 Answers

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,423 Points

Perhaps it's time to start fresh. If you don't have a need to back up to previous versions the courses models, you can choose to clear all 'coursesmigrations (by deleting those files) and re-init the migrations for the β€˜courses app. This should reset the migrations to match you current models.

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,423 Points

Looking at your migrations list it appears you have not applied all of the migrations (those with [ ]):

courses  
 [X] 0001_initial  
 [X] 0002_step  
 [X] 0003_auto_20150601_1513  
 [ ] 0004_auto_20160216_2055  
 [X] 0005_quiz  
 [ ] 0006_auto_20160217_1742  
 [X] 0007_answer  
 [ ] 0008_multiplechoicequestion  

Try resetting the state to before the first skipped migration.

$ ./manage.py migrate courses 0003_auto_20150601_1513

Rerun $ ./manage.py showmigrations courses to verify unapplied (unchecked) migration 0005 and 0007.

Then rerun all unapplied migrations

$ ./manage.py migrate courses

Derrick Kearney
Derrick Kearney
2,962 Points

Chris, Thanks for your effort. So I followed your directions exactly.

./manage.py showmigrations courses                     
courses    
 [X] 0001_initial    
 [X] 0002_step    
 [X] 0003_auto_20150601_1513     
 [ ] 0004_auto_20160216_2055    
 [ ] 0005_quiz     
 [ ] 0006_auto_20160217_1742   
 [ ] 0007_answer   
 [ ] 0008_multiplechoicequestion   

But that:

django.db.utils.OperationalError: no such table: courses_step

still persists.

Chris Freeman
Chris Freeman
Treehouse Moderator 68,423 Points

What happens when you run each migration, one at a time, starting with

$ ./manage.py migrate courses  0004_auto_20160216_2055  

$ ./manage.py migrate courses  0005_quiz  

$ ./manage.py migrate courses  0006_auto_20160217_1742  

$ ./manage.py migrate courses  0007_answer  

$ ./manage.py migrate courses  0008_multiplechoicequestion  

Run showmigrations between each step to check all previous were applied.