0
votes

I am struggling to get my Django 1.10 app deployed to Heroku. When I push this site to Heroku, I get the application error:

ProgrammingError at /homelibrary/
relation "catalog_book" does not exist
LINE 1: SELECT COUNT(*) AS "__count" FROM "catalog_book"

Ever since I changed the default Sqlite3 database to Postgres, it hasn't run locally and I get errors every time I migrate. I have tried:

python3 manage.py makemigrations
python3 manage.py makemigrations catalog
python3 manage.py syncdb
python3 manage.py migrate catalog --fake
python3 manage.py migrate --fake

I get this error every time:

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')

Sometimes I get variations on the last line, such as

django.db.migrations.exceptions.NodeNotFoundError: Migration catalog.0003_book_sub_title dependencies reference nonexistent parent node  ('homelibrary', '0002_auto_20170107_2158')

and

django.db.migrations.exceptions.NodeNotFoundError: Migration catalog.0006_auto_20170107_2320 dependencies reference nonexistent parent node ('homelibrary', '0005_auto_20170107_2300')

Does anyone have any suggestions what's going wrong?

UPDATE:

I deleted all the migration files with:

find . -path "*/migrations/*.py" -not -name "__init__.py" -delete
find . -path "*/migrations/*.pyc"  -delete

Now I am unable to push to heroku master and get an error that /tmp/build_e7c89faecaf0e6bc9724a9a2be271ba4/static does not exist:

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'

Project structure

---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

Catalog/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)
1
well if you use --fake the tables will not be created! - e4c5
Yes, I realize that, but I gave it a go from reading another Q&A on here. - cssidy
Have you tried running: heroku run python manage.py migrate - JakeC
@JakeConway yes, same error. - cssidy
Any chance you've moved/refactored your migrations? The error means that a migration is looking for (and failing to find) a dependency. Look at each migration and make sure that the 'dependencies' at the top reference migrations that actually exist. If you have just switched to PostgreSQL, you may should consider starting over - delete all your existing migrations and run makemigrations again. - bimsapi

1 Answers

0
votes

Try running each migration including dependencies separately.

python manage.py migrate auth
python manage.py migrate sites
python manage.py migrate <your-app>

I was able to get around some problems like this.