我正在努力将我的Django 1.10应用程序部署到Heroku。当我将此站点推送到Heroku时,我收到应用程序错误:
ProgrammingError at /homelibrary/
relation "catalog_book" does not exist
LINE 1: SELECT COUNT(*) AS "__count" FROM "catalog_book"
自从我将默认的Sqlite3数据库更改为Postgres后,它就无法在本地运行,每次迁移时都会出错。我试过了:
python3 manage.py makemigrations
python3 manage.py makemigrations catalog
python3 manage.py syncdb
python3 manage.py migrate catalog --fake
python3 manage.py migrate --fake
我每次都会收到此错误:
Traceback (most recent call last):
File "manage.py", line 22, in <module>
execute_from_command_line(sys.argv)
File "/usr/local/lib/python3.5/dist-packages/django/core/management/__init__.py", line 367, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python3.5/dist-packages/django/core/management/__init__.py", line 359, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/local/lib/python3.5/dist-packages/django/core/management/base.py", line 294, in run_from_argv
self.execute(*args, **cmd_options)
File "/usr/local/lib/python3.5/dist-packages/django/core/management/base.py", line 345, in execute
output = self.handle(*args, **options)
File "/usr/local/lib/python3.5/dist-packages/django/core/management/commands/makemigrations.py", line 95, in handle
loader = MigrationLoader(None, ignore_no_migrations=True)
File "/usr/local/lib/python3.5/dist-packages/django/db/migrations/loader.py", line 52, in __init__
self.build_graph()
File "/usr/local/lib/python3.5/dist-packages/django/db/migrations/loader.py", line 268, in build_graph
raise exc
File "/usr/local/lib/python3.5/dist-packages/django/db/migrations/loader.py", line 238, in build_graph
self.graph.validate_consistency()
File "/usr/local/lib/python3.5/dist-packages/django/db/migrations/graph.py", line 261, in validate_consistency
[n.raise_error() for n in self.node_map.values() if isinstance(n, DummyNode)]
File "/usr/local/lib/python3.5/dist-packages/django/db/migrations/graph.py", line 261, in <listcomp>
[n.raise_error() for n in self.node_map.values() if isinstance(n, DummyNode)]
File "/usr/local/lib/python3.5/dist-packages/django/db/migrations/graph.py", line 104, in raise_error
raise NodeNotFoundError(self.error_message, self.key, origin=self.origin)
django.db.migrations.exceptions.NodeNotFoundError: Migration catalog.0004_auto_20170107_2239 dependencies reference nonexistent parent node ('homelibrary', '0003_book_sub_title')
有时我会在最后一行获得变体,例如
django.db.migrations.exceptions.NodeNotFoundError: Migration catalog.0003_book_sub_title dependencies reference nonexistent parent node ('homelibrary', '0002_auto_20170107_2158')
和
django.db.migrations.exceptions.NodeNotFoundError: Migration catalog.0006_auto_20170107_2320 dependencies reference nonexistent parent node ('homelibrary', '0005_auto_20170107_2300')
有没有人有什么建议会出错?
更新
我删除了所有迁移文件:
find . -path "*/migrations/*.py" -not -name "__init__.py" -delete
find . -path "*/migrations/*.pyc" -delete
现在我无法推送到heroku master并收到/ tmp / build_e7c89faecaf0e6bc9724a9a2be271ba4 / static不存在的错误:
python manage.py collectstatic --noinput
remote: Traceback (most recent call last):
remote: File "manage.py", line 22, in <module>
remote: execute_from_command_line(sys.argv)
remote: File "/app/.heroku/python/lib/python3.5/site- packages/django/core/management/__init__.py", line 367, in execute_from_command_line
remote: utility.execute()
remote: File "/app/.heroku/python/lib/python3.5/site-packages/django/core/management/__init__.py", line 359, in execute
remote: self.fetch_command(subcommand).run_from_argv(self.argv)
remote: File "/app/.heroku/python/lib/python3.5/site-packages/django/core/management/base.py", line 294, in run_from_argv
remote: self.execute(*args, **cmd_options)
remote: File "/app/.heroku/python/lib/python3.5/site-packages/django/core/management/base.py", line 345, in execute
remote: output = self.handle(*args, **options)
remote: File "/app/.heroku/python/lib/python3.5/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 193, in handle
remote: collected = self.collect()
remote: File "/app/.heroku/python/lib/python3.5/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 115, in collect
remote: for path, storage in finder.list(self.ignore_patterns):
remote: File "/app/.heroku/python/lib/python3.5/site-packages/django/contrib/staticfiles/finders.py", line 112, in list
remote: for path in utils.get_files(storage, ignore_patterns):
remote: File "/app/.heroku/python/lib/python3.5/site-packages/django/contrib/staticfiles/utils.py", line 28, in get_files
remote: directories, files = storage.listdir(location)
remote: File "/app/.heroku/python/lib/python3.5/site-packages/django/core/files/storage.py", line 399, in listdir
remote: for entry in os.listdir(path):
remote: FileNotFoundError: [Errno 2] No such file or directory: '/tmp/build_e7c89faecaf0e6bc9724a9a2be271ba4/static'
项目结构
---homelibrary
---catalog
---migrations
---static
---css
---images
favicon.ico
---templates
__init__.py
admin.py
apps.py
forms.py
models.py
tests.py
urls.py
views.py
---homelibrary
__init__.py
settings.py
urls.py
wsgi.py
---templates (for generic, cross-site forms)
---venv
.gitignore.txt
db.sqlite3
LICENSE
manage.py
Procfile
README.md
requirements.txt
runtime.txt
录/ models.py
from django.db import models
from django.contrib.auth.models import User
class Genre(models.Model):
"""
Model representing a book genre (e.g. Science Fiction, Non Fiction).
"""
name = models.CharField(max_length=200, help_text="Enter a book genre (e.g. Science Fiction, French Poetry etc.)")
def __str__(self):
"""
String for representing the Model object (in Admin site etc.)
"""
return self.name
class Language(models.Model):
"""
Model representing a Language (e.g. English, French, Japanese, etc.)
"""
name = models.CharField(max_length=200,
help_text="Enter a the book's natural language (e.g. English, French, Japanese etc.)")
def __str__(self):
"""
String for representing the Model object (in Admin site etc.)
"""
return self.name
from django.urls import reverse # Used to generate URLs by reversing the URL patterns
class Book(models.Model):
"""
Model representing a book (but not a specific copy of a book).
"""
title = models.CharField(max_length=200)
sub_title = models.CharField(max_length=300, null=True, blank=True)
author = models.ForeignKey('Author', on_delete=models.SET_NULL, null=True)
# Foreign Key used because book can only have one author, but authors can have multiple books
# Author as a string rather than object because it hasn't been declared yet in the file.
summary = models.TextField(max_length=1000, help_text="Enter a brief description of the book")
isbn = models.CharField('ISBN', max_length=13, null=True, blank=True,
help_text='10-13 Character <a href="https://www.isbn-international.org/content/what-isbn">ISBN number</a>')
genre = models.ManyToManyField(Genre, help_text="Select a genre for this book")
language = models.ForeignKey('Language', on_delete=models.SET_NULL, null=True)
# ManyToManyField used because genre can contain many books. Books can cover many genres.
# Genre class has already been defined so we can specify the object above.
def __str__(self):
"""
String for representing the Model object.
"""
return self.title
def get_absolute_url(self):
"""
Returns the url to access a particular book instance.
"""
return reverse('book-detail', args=[str(self.id)])
def display_genre(self):
"""
Creates a string for the Genre. This is required to display genre in Admin.
"""
return ', '.join([genre.name for genre in self.genre.all()[:3]])
display_genre.short_description = 'Genre'
import uuid # Required for unique book instances
from datetime import date
class BookInstance(models.Model):
"""
Model representing a specific copy of a book (i.e. that can be borrowed from the library).
"""
id = models.UUIDField(primary_key=True, default=uuid.uuid4,
help_text="Unique ID for this particular book across whole library")
book = models.ForeignKey('Book', on_delete=models.SET_NULL, null=True)
imprint = models.CharField(max_length=200, null=True, blank=True)
due_back = models.DateField(null=True, blank=True)
borrower = models.ForeignKey(User, on_delete=models.SET_NULL, null=True, blank=True)
@property
def is_overdue(self):
if date.today() > self.due_back:
return True
return False
LOAN_STATUS = (
('d', 'Maintenance'),
('o', 'On loan'),
('a', 'Available'),
('r', 'Reserved'),
)
status = models.CharField(max_length=1, choices=LOAN_STATUS, blank=True, default='a', help_text='Book availability')
class Meta:
ordering = ["due_back"]
permissions = (("can_mark_returned", "Set book as returned"),)
def __str__(self):
"""
String for representing the Model object
"""
return '%s (%s)' % (self.id, self.book.title)
class Author(models.Model):
"""
Model representing an author.
"""
first_name = models.CharField(max_length=100)
last_name = models.CharField(max_length=100)
date_of_birth = models.DateField(null=True, blank=True)
def get_absolute_url(self):
"""
Returns the url to access a particular author instance.
"""
return reverse('author-detail', args=[str(self.id)])
def __str__(self):
"""
String for representing the Model object.
"""
return '%s, %s' % (self.last_name, self.first_name)
答案 0 :(得分:0)
尝试单独运行每个迁移,包括依赖项。
python manage.py migrate auth
python manage.py migrate sites
python manage.py migrate <your-app>
我能解决一些像这样的问题。