Django - Migrating from Sqlite3 to Postgresql
<p>I'm trying to deploy my Django app in Heroku, so I have to switch to PostgreSQL and I've been following these <a href="http://stackoverflow.com/questions/28648695/migrate-django-development-database-sql3-to-heroku">steps</a></p>

<p>However when I run <code>python manage.py migrate</code></p>

<p>I get the following error:</p>

<pre><code>C:\Users\admin\trailers&gt;python manage.py migrate
Operations to perform:
  Apply all migrations: auth, movies, sessions, admin, contenttypes
Running migrations:
  Rendering model states... DONE
  Applying movies.0012_auto_20160915_1904...Traceback (most recent call last):
  File "C:\Program Files (x86)\Python35-32\lib\site-packages\django\db\backends\
utils.py", line 64, in execute
    return self.cursor.execute(sql, params)
psycopg2.ProgrammingError: foreign key constraint "movies_movie_genre_genre_id_d
9d93fd9_fk_movies_genre_id" cannot be implemented
DETAIL:  Key columns "genre_id" and "id" are of incompatible types: integer and
character varying.


The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "manage.py", line 10, in &lt;module&gt;
    execute_from_command_line(sys.argv)
  File "C:\Program Files (x86)\Python35-32\lib\site-packages\django\core\managem
ent\__init__.py", line 350, in execute_from_command_line
    utility.execute()
  File "C:\Program Files (x86)\Python35-32\lib\site-packages\django\core\managem
ent\__init__.py", line 342, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "C:\Program Files (x86)\Python35-32\lib\site-packages\django\core\managem
ent\base.py", line 348, in run_from_argv
    self.execute(*args, **cmd_options)
  File "C:\Program Files (x86)\Python35-32\lib\site-packages\django\core\managem
ent\base.py", line 399, in execute
    output = self.handle(*args, **options)
  File "C:\Program Files (x86)\Python35-32\lib\site-packages\django\core\managem
ent\commands\migrate.py", line 200, in handle
    executor.migrate(targets, plan, fake=fake, fake_initial=fake_initial)
  File "C:\Program Files (x86)\Python35-32\lib\site-packages\django\db\migration
s\executor.py", line 92, in migrate
    self._migrate_all_forwards(plan, full_plan, fake=fake, fake_initial=fake_ini
tial)
  File "C:\Program Files (x86)\Python35-32\lib\site-packages\django\db\migration
s\executor.py", line 121, in _migrate_all_forwards
    state = self.apply_migration(state, migration, fake=fake, fake_initial=fake_
initial)
  File "C:\Program Files (x86)\Python35-32\lib\site-packages\django\db\migration
s\executor.py", line 198, in apply_migration
    state = migration.apply(state, schema_editor)
  File "C:\Program Files (x86)\Python35-32\lib\site-packages\django\db\migration
s\migration.py", line 123, in apply
    operation.database_forwards(self.app_label, schema_editor, old_state, projec
t_state)
  File "C:\Program Files (x86)\Python35-32\lib\site-packages\django\db\migration
s\operations\fields.py", line 201, in database_forwards
    schema_editor.alter_field(from_model, from_field, to_field)
  File "C:\Program Files (x86)\Python35-32\lib\site-packages\django\db\backends\
base\schema.py", line 482, in alter_field
    old_db_params, new_db_params, strict)
  File "C:\Program Files (x86)\Python35-32\lib\site-packages\django\db\backends\
base\schema.py", line 634, in _alter_field
    params,
  File "C:\Program Files (x86)\Python35-32\lib\site-packages\django\db\backends\
base\schema.py", line 110, in execute
    cursor.execute(sql, params)
  File "C:\Program Files (x86)\Python35-32\lib\site-packages\django\db\backends\
utils.py", line 79, in execute
    return super(CursorDebugWrapper, self).execute(sql, params)
  File "C:\Program Files (x86)\Python35-32\lib\site-packages\django\db\backends\
utils.py", line 64, in execute
    return self.cursor.execute(sql, params)
  File "C:\Program Files (x86)\Python35-32\lib\site-packages\django\db\utils.py"
, line 95, in __exit__
    six.reraise(dj_exc_type, dj_exc_value, traceback)
  File "C:\Program Files (x86)\Python35-32\lib\site-packages\django\utils\six.py
", line 685, in reraise
    raise value.with_traceback(tb)
  File "C:\Program Files (x86)\Python35-32\lib\site-packages\django\db\backends\
utils.py", line 64, in execute
    return self.cursor.execute(sql, params)
django.db.utils.ProgrammingError: foreign key constraint "movies_movie_genre_gen
re_id_d9d93fd9_fk_movies_genre_id" cannot be implemented
DETAIL:  Key columns "genre_id" and "id" are of incompatible types: integer and
character varying.
</code></pre>

<p>Here is my <strong>models.py</strong></p>

<pre><code>class Genre(models.Model):
    id = models.IntegerField(primary_key=True)
    genre = models.CharField(max_length=255)

class Person(models.Model):
    name = models.CharField(max_length=128)

class Movie(models.Model):
    title = models.CharField(max_length=511)
    tmdb_id = models.IntegerField(null=True, blank=True, unique=True)
    release = models.DateField(null=True, blank=True)
    poster = models.TextField(max_length=500, null=True)
    backdrop = models.TextField(max_length=500, null=True, blank=True)
    popularity = models.TextField(null=True, blank=True)
    runtime = models.IntegerField(null=True, blank=True)
    description = models.TextField(null=True, blank=True)
    director = models.ManyToManyField(Person, related_name="directed_movies")
    actors = models.ManyToManyField(Person, related_name="acted_movies")
    genre = models.ManyToManyField(Genre)

class Trailer(models.Model):
    movie = models.ForeignKey(Movie, on_delete=models.CASCADE, null=True)
    link = models.CharField(max_length=100)
</code></pre>

<p>I can't figure out what's wrong with my code, any help would be appreciated! </p>

<p><strong>Edit</strong>: I tried removing the id field from the Genre class and I still get the same error</p>

<p>You must use this command:</p>

<pre><code>python manage.py makemigrations
</code></pre>

<p>before your command</p>

<pre><code>python manage.py migrate
</code></pre>

python django postgresql heroku