Note that there are some explanatory texts on larger screens.

plurals
  1. POModelForeign key fails to create a column id linked to the object in Django
    primarykey
    data
    text
    <p>I can't figure out why the <code>ForeignKey</code> is not working in my <code>models.py</code>. </p> <p>I closely followed the tutorial and all I need to do is to make <code>Games</code> a part of <code>Department</code> (same with <code>Choices</code> and part of the <code>Poll</code>). Same games can be part of different departments. </p> <p>Here's the code for my <code>models.py</code>:</p> <pre><code>from django.db import models class Department(models.Model): name = models.CharField(max_length=200) def __unicode__(self): return self.name class Game(models.Model): department = models.ForeignKey(Department) name_of_the_game = models.CharField(max_length=200) def __unicode__(self): return self.name_of_the_game </code></pre> <p>I created the SQLite tables and did everything like in the tutorial. </p> <p>This is the error that it gives me in python shell: </p> <pre><code>&gt;&gt;&gt; from logins.models import Department, Game &gt;&gt;&gt; p = Department.objects.get(pk = 1) &gt;&gt;&gt; p.game_set.all() Traceback (most recent call last): File "&lt;console&gt;", line 1, in &lt;module&gt; File "/Library/Python/2.7/site-packages/django/db/models/query.py", line 71, in __repr__ data = list(self[:REPR_OUTPUT_SIZE + 1]) File "/Library/Python/2.7/site-packages/django/db/models/query.py", line 96, in __iter__ self._fetch_all() File "/Library/Python/2.7/site-packages/django/db/models/query.py", line 854, in _fetch_all self._result_cache = list(self.iterator()) File "/Library/Python/2.7/site-packages/django/db/models/query.py", line 220, in iterator for row in compiler.results_iter(): File "/Library/Python/2.7/site-packages/django/db/models/sql/compiler.py", line 710, in results_iter for rows in self.execute_sql(MULTI): File "/Library/Python/2.7/site-packages/django/db/models/sql/compiler.py", line 781, in execute_sql cursor.execute(sql, params) File "/Library/Python/2.7/site-packages/django/db/backends/util.py", line 69, in execute return super(CursorDebugWrapper, self).execute(sql, params) File "/Library/Python/2.7/site-packages/django/db/backends/util.py", line 53, in execute return self.cursor.execute(sql, params) File "/Library/Python/2.7/site-packages/django/db/utils.py", line 99, in __exit__ six.reraise(dj_exc_type, dj_exc_value, traceback) File "/Library/Python/2.7/site-packages/django/db/backends/util.py", line 53, in execute return self.cursor.execute(sql, params) File "/Library/Python/2.7/site-packages/django/db/backends/sqlite3/base.py", line 450, in execute return Database.Cursor.execute(self, query, params) OperationalError: no such column: logins_game.department_id </code></pre> <p>Maybe I am just missing some very basic step, but even after reading related docs on Django site, I can't seem to figure it out. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload