Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ssh/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Django 1.7与Heroku Postgres的迁移错误_Python_Django_Postgresql_Heroku - Fatal编程技术网

Python Django 1.7与Heroku Postgres的迁移错误

Python Django 1.7与Heroku Postgres的迁移错误,python,django,postgresql,heroku,Python,Django,Postgresql,Heroku,我正在使用Python3.3.4和Django 1.7将一个应用程序部署到带有Heroku Postgresql的Heroku。我的应用程序在本地使用sqlite运行良好。 当我运行用于初始迁移的命令时: heroku run python manage.py 我收到一个迁移错误: (storage_project)Edu222-Macbook-Pro:storage educalvachi$ heroku run python manage.py migrate Running `pytho

我正在使用Python3.3.4和Django 1.7将一个应用程序部署到带有Heroku Postgresql的Heroku。我的应用程序在本地使用sqlite运行良好。 当我运行用于初始迁移的命令时:

heroku run python manage.py
我收到一个迁移错误:

(storage_project)Edu222-Macbook-Pro:storage educalvachi$ heroku run python manage.py migrate
Running `python manage.py migrate` attached to terminal... up, run.9874
Operations to perform:
  Synchronize unmigrated apps: django_admin_bootstrapped
  Apply all migrations: contenttypes, core, admin, sessions, auth
Synchronizing apps without migrations:
  Creating tables...
  Installing custom SQL...
  Installing indexes...
Running migrations:
  Applying contenttypes.0001_initial... OK
  Applying auth.0001_initial... OK
  Applying admin.0001_initial... OK
  Applying core.0001_initial... OK
  Applying core.0002_auto_20140530_0152... OK
  Applying core.0003_auto_20140819_1955... OK
  Applying core.0004_auto_20140822_1426... OK
  Applying core.0005_auto_20140822_1908... OK
  Applying core.0006_auto_20140824_0021...Traceback (most recent call last):
  File "/app/.heroku/python/lib/python3.3/site-packages/django/db/backends/utils.py", line 65, in execute
return self.cursor.execute(sql, params)
psycopg2.ProgrammingError: multiple primary keys for table "core_broca" are not allowed


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

Traceback (most recent call last):
  File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
  File "/app/.heroku/python/lib/python3.3/site-packages/django/core/management/__init__.py", line 385, in execute_from_command_line
utility.execute()
  File "/app/.heroku/python/lib/python3.3/site-packages/django/core/management/__init__.py", line 377, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/app/.heroku/python/lib/python3.3/site-packages/django/core/management/base.py", line 288, in run_from_argv
self.execute(*args, **options.__dict__)
  File "/app/.heroku/python/lib/python3.3/site-packages/django/core/management/base.py", line 338, in execute
output = self.handle(*args, **options)
  File "/app/.heroku/python/lib/python3.3/site-packages/django/core/management/commands/migrate.py", line 160, in handle
executor.migrate(targets, plan, fake=options.get("fake", False))
  File "/app/.heroku/python/lib/python3.3/site-packages/django/db/migrations/executor.py", line 63, in migrate
self.apply_migration(migration, fake=fake)
  File "/app/.heroku/python/lib/python3.3/site-packages/django/db/migrations/executor.py", line 97, in apply_migration
migration.apply(project_state, schema_editor)
  File "/app/.heroku/python/lib/python3.3/site-packages/django/db/migrations/migration.py", line 107, in apply
operation.database_forwards(self.app_label, schema_editor, project_state, new_state)
  File "/app/.heroku/python/lib/python3.3/site-packages/django/db/migrations/operations/fields.py", line 37, in database_forwards
field,
  File "/app/.heroku/python/lib/python3.3/site-packages/django/db/backends/schema.py", line 411, in add_field
self.execute(sql, params)
  File "/app/.heroku/python/lib/python3.3/site-packages/django/db/backends/schema.py", line 98, in execute
cursor.execute(sql, params)
  File "/app/.heroku/python/lib/python3.3/site-packages/django/db/backends/utils.py", line 81, in execute
return super(CursorDebugWrapper, self).execute(sql, params)
  File "/app/.heroku/python/lib/python3.3/site-packages/django/db/backends/utils.py", line 65, in execute
return self.cursor.execute(sql, params)
  File "/app/.heroku/python/lib/python3.3/site-packages/django/db/utils.py", line 94, in __exit__
six.reraise(dj_exc_type, dj_exc_value, traceback)
  File "/app/.heroku/python/lib/python3.3/site-packages/django/utils/six.py", line 549, in reraise
raise value.with_traceback(tb)
  File "/app/.heroku/python/lib/python3.3/site-packages/django/db/backends/utils.py", line 65, in execute
return self.cursor.execute(sql, params)
django.db.utils.ProgrammingError: multiple primary keys for table "core_broca" are not allowed

有什么想法吗?感谢您的帮助。

您的表
Broca
似乎给出了多个主键的错误。如果这是您的第一次安装,您是否尝试过heroku运行python manage.py syncdb?您好,我尝试过syncdb,得到了相同的结果。根据Django 1.7 releaso中的说明,看起来它将取代syncdb:“syncdb已被弃用并被migrate取代。别担心-对syncdb的调用仍将像以前一样工作”。
from django.db import models

class Persona(models.Model):
    identificacion = models.CharField(max_length=20)
    name = models.CharField(max_length=164)

    def __str__(self):
        return self.name

class Herramienta(models.Model):
    marca = models.CharField(max_length=90)
    tipo = models.CharField(max_length=90, blank=True)
    codigo_id = models.CharField(max_length=15, unique=True)
    prestamos = models.ManyToManyField(Persona, through='Prestamo')

    def __str__(self):
        return self.marca + " " + self.tipo + " " + self.codigo_id

class Prestamo(models.Model):
    herramienta = models.ForeignKey(Herramienta)
    persona = models.ForeignKey(Persona)
    fecha_prestamo = models.DateTimeField(auto_now_add=True)
    fecha_devolucion = models.DateTimeField(null=True, blank=True)

    def __str__(self):
        return "Préstamo a " + self.persona.name

class Destornillador(Herramienta):
    TAMANO_CHOICES = (
        ('Largo', 'Largo'),
        ('Medio', 'Medio'),
        ('Junior', 'Junior'),
    )
    tamano = models.CharField(max_length=80, choices=TAMANO_CHOICES,
                default='Junior')

    def __str__(self):
        return "Destornillador de" + " tamano " + self.tamano

class Llave(Herramienta):
    tamano = models.CharField(max_length=80)

class Copa(Herramienta):
    tamano = models.CharField(max_length=80)
    mando = models.CharField(max_length=80)

    def __str__(self):
        return "copa " + self.tamano

class Pistola(Herramienta):
    dimension = models.IntegerField(max_length=80)
    torque = models.IntegerField(max_length=80)
    presion_aire = models.IntegerField(max_length=80)

class Playo(Herramienta):
    tamano = models.CharField(max_length=80)
    funcion = models.CharField(max_length=90)

class Martillo(Herramienta):
    material = models.CharField(max_length=90)

class Broca(Herramienta):
    utilidad = models.CharField(max_length=90)
    tamano = models.CharField(max_length=80)

    def __str__(self):
        return "Broca de " + self.utilidad + " de " + self.tamano

class Lima(Herramienta):
    tamano = models.CharField(max_length=80)

class Generico(Herramienta):
    caracteristicas = models.CharField(max_length=90)

class InstrumentoDeMedida(Herramienta):
    rango = models.CharField(max_length=80)
    escala = models.CharField(max_length=80, blank=True)