sql - Error: Table 'django_db.polls_question' doesn't exist [SQLCode: 1146], [SQLState: 42S02] -
i following tutorial on
https://docs.djangoproject.com/en/1.10/intro/tutorial02/.
i have reached section : playing api¶
once you’re in shell, explore database api:
>>> polls.models import question, choice # import model classes wrote. # no questions in system yet. >>> question.objects.all()
this gives error :
error: table 'django_db.polls_question' doesn't exist [sqlcode: 1146], [sqlstate: 42s02]
before above error : prints :
>>> traceback (most recent call last): file "<console>", line 1, in <module> file "/usr/local/lib/jython/lib/site-packages/django-1.8.16-py2.7.egg/django/db/models/query.py", line 138, in __repr__ data = list(self[:repr_output_size + 1]) file "/usr/local/lib/jython/lib/site-packages/django-1.8.16-py2.7.egg/django/db/models/query.py", line 162, in __iter__ self._fetch_all() file "/usr/local/lib/jython/lib/site-packages/django-1.8.16-py2.7.egg/django/db/models/query.py", line 965, in _fetch_all self._result_cache = list(self.iterator()) file "/usr/local/lib/jython/lib/site-packages/django-1.8.16-py2.7.egg/django/db/models/query.py", line 238, in iterator results = compiler.execute_sql() file "/usr/local/lib/jython/lib/site-packages/django-1.8.16-py2.7.egg/django/db/models/sql/compiler.py", line 840, in execute_sql cursor.execute(sql, params) file "/usr/local/lib/jython/lib/site-packages/django-1.8.16-py2.7.egg/django/db/backends/utils.py", line 79, in execute return super(cursordebugwrapper, self).execute(sql, params) file "/usr/local/lib/jython/lib/site-packages/django-1.8.16-py2.7.egg/django/db/backends/utils.py", line 64, in execute return self.cursor.execute(sql, params) file "/usr/local/lib/jython/lib/site-packages/django-1.8.16-py2.7.egg/django/db/utils.py", line 98, in __exit__ six.reraise(dj_exc_type, dj_exc_value, traceback) file "/usr/local/lib/jython/lib/site-packages/django-1.8.16-py2.7.egg/django/db/backends/utils.py", line 64, in execute return self.cursor.execute(sql, params) file "/usr/local/lib/jython/lib/site-packages/django_jython-1.8.0b3-py2.7.egg/doj/db/backends/__init__.py", line 185, in execute self.cursor.execute(sql, params)
i went mysql, same database check existing tables.
mysql> show tables; +----------------------------+ | tables_in_django_db | +----------------------------+ | auth_group | | auth_group_permissions | | auth_permission | | auth_user | | auth_user_groups | | auth_user_user_permissions | | django_admin_log | | django_content_type | | django_migrations | | django_session | | polls_choice | | polls_poll | +----------------------------+ 12 rows in set (0.00 sec)
after describing tables, realized polls_question being renamed polls_poll
$jython manage.py sqlmigrate polls 0001 begin; create table `polls_choice` (`id` integer auto_increment not null primary key, `choice_text` varchar(200) not null, `votes` integer not null); create table `polls_question` (`id` integer auto_increment not null primary key, `question_text` varchar(200) not null, `pub_date` datetime not null); alter table `polls_choice` add column `question_id` integer not null; alter table `polls_choice` alter column `question_id` drop default; create index `polls_choice_7aa0f6ee` on `polls_choice` (`question_id`); alter table `polls_choice` add constraint `polls_choice_question_id_54f1d7bd_fk_polls_question_id` foreign key (`question_id`) references `polls_question` (`id`); commit;
and in mysql,
mysql> describe polls_poll; +----------+--------------+------+-----+---------+----------------+ | field | type | null | key | default | | +----------+--------------+------+-----+---------+----------------+ | id | int(11) | no | pri | null | auto_increment | | question | varchar(200) | no | | null | | | pub_date | datetime | no | | null | | +----------+--------------+------+-----+---------+----------------+ 3 rows in set (0.00 sec)
i have tried searching extensively in other answers unable find solution.
Comments
Post a Comment