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 trialSimin Hajizadeh
3,072 PointsOperationalError
When I type Course.objects.all() I get an Import error while I have imported Course class. What does this error mean? And how can I fix it? I tried manage.py migrate and manage.py syncdb, while it says :Unknown command: 'syncdb'.
what should I do??
OperationalError Traceback (most recent call last) /Users/simin/anaconda/lib/python3.5/site-packages/django/db/backends/utils.py in execute(self, sql, params) 63 else: ---> 64 return self.cursor.execute(sql, params) 65
/Users/simin/anaconda/lib/python3.5/site-packages/django/db/backends/sqlite3/base.py in execute(self, query, params) 336 query = self.convert_query(query) --> 337 return Database.Cursor.execute(self, query, params) 338
OperationalError: no such table: courses_course
The above exception was the direct cause of the following exception:
OperationalError Traceback (most recent call last) <ipython-input-6-6970514bfc33> in <module>() ----> 1 c.save()
/Users/simin/anaconda/lib/python3.5/site-packages/django/db/models/base.py in save(self, force_insert, force_update, using, update_fields) 794 795 self.save_base(using=using, force_insert=force_insert, --> 796 force_update=force_update, update_fields=update_fields) 797 save.alters_data = True 798
/Users/simin/anaconda/lib/python3.5/site-packages/django/db/models/base.py in save_base(self, raw, force_insert, force_update, using, update_fields) 822 if not raw: 823 self._save_parents(cls, using, update_fields) --> 824 updated = self._save_table(raw, cls, force_insert, force_update, using, update_fields) 825 # Store the database on which the object was saved 826 self._state.db = using
/Users/simin/anaconda/lib/python3.5/site-packages/django/db/models/base.py in _save_table(self, raw, cls, force_insert, force_update, using, update_fields) 906 907 update_pk = bool(meta.has_auto_field and not pk_set) --> 908 result = self._do_insert(cls._base_manager, using, fields, update_pk, raw) 909 if update_pk: 910 setattr(self, meta.pk.attname, result)
/Users/simin/anaconda/lib/python3.5/site-packages/django/db/models/base.py in _do_insert(self, manager, using, fields, update_pk, raw) 945 """ 946 return manager._insert([self], fields=fields, return_id=update_pk, --> 947 using=using, raw=raw) 948 949 def delete(self, using=None, keep_parents=False):
/Users/simin/anaconda/lib/python3.5/site-packages/django/db/models/manager.py in manager_method(self, *args, **kwargs) 83 def create_method(name, method): 84 def manager_method(self, *args, **kwargs): ---> 85 return getattr(self.get_queryset(), name)(*args, **kwargs) 86 manager_method.name = method.name 87 manager_method.doc = method.doc
/Users/simin/anaconda/lib/python3.5/site-packages/django/db/models/query.py in _insert(self, objs, fields, return_id, raw, using) 1043 query = sql.InsertQuery(self.model) 1044 query.insert_values(fields, objs, raw=raw) -> 1045 return query.get_compiler(using=using).execute_sql(return_id) 1046 _insert.alters_data = True 1047 _insert.queryset_only = False
/Users/simin/anaconda/lib/python3.5/site-packages/django/db/models/sql/compiler.py in execute_sql(self, return_id) 1052 with self.connection.cursor() as cursor: 1053 for sql, params in self.as_sql(): -> 1054 cursor.execute(sql, params) 1055 if not (return_id and cursor): 1056 return
/Users/simin/anaconda/lib/python3.5/site-packages/django/db/backends/utils.py in execute(self, sql, params) 77 start = time() 78 try: ---> 79 return super(CursorDebugWrapper, self).execute(sql, params) 80 finally: 81 stop = time()
/Users/simin/anaconda/lib/python3.5/site-packages/django/db/backends/utils.py in execute(self, sql, params) 62 return self.cursor.execute(sql) 63 else: ---> 64 return self.cursor.execute(sql, params) 65 66 def executemany(self, sql, param_list):
/Users/simin/anaconda/lib/python3.5/site-packages/django/db/utils.py in exit(self, exc_type, exc_value, traceback) 92 if dj_exc_type not in (DataError, IntegrityError): 93 self.wrapper.errors_occurred = True ---> 94 six.reraise(dj_exc_type, dj_exc_value, traceback) 95 96 def call(self, func):
/Users/simin/anaconda/lib/python3.5/site-packages/django/utils/six.py in reraise(tp, value, tb) 683 value = tp() 684 if value.traceback is not tb: --> 685 raise value.with_traceback(tb) 686 raise value 687
/Users/simin/anaconda/lib/python3.5/site-packages/django/db/backends/utils.py in execute(self, sql, params) 62 return self.cursor.execute(sql) 63 else: ---> 64 return self.cursor.execute(sql, params) 65 66 def executemany(self, sql, param_list):
/Users/simin/anaconda/lib/python3.5/site-packages/django/db/backends/sqlite3/base.py in execute(self, query, params) 335 return Database.Cursor.execute(self, query) 336 query = self.convert_query(query) --> 337 return Database.Cursor.execute(self, query, params) 338 339 def executemany(self, query, param_list):
OperationalError: no such table: courses_course
2 Answers
ursaminor
11,271 PointsI'm guessing you didn't make migrations before applying it (migrate), since it's not finding the table.
python manage.py makemigrations
python manage.py migrate
Vasileios Koukoutsas
13,864 Pointstry this as well before creating the new object
python manage.py migrate --run-syncdb
Andreas cormack
Python Web Development Techdegree Graduate 33,011 PointsAndreas cormack
Python Web Development Techdegree Graduate 33,011 PointsHi Simin
Post your Course model and view code. Hard to see what the problem is without the code.