Django models foreign key not recognizing 'QueryString' BaseObject

I am currently working on a Django 1.5.2 project within a Docker instance that speaks with a mysql database in a separate Docker instance. I am trying to create a Many to Many relationship between two tables by creating a middle table that contains two foreign keys that point to the two tables that need connecting. The problem arises when I run python syncdb and it spits out the following error to the terminal: NameError: name 'QueryString' is not defined. QueryString is clearly defined in my models.

Here are my Models…

  • Docker Mac Beta and container connecting to host ports?
  • Is it possible to mount docker volume to a different filesystem?
  • Installing Zookeeper on offline openshift
  • How to allow my host IP address in the PostgreSQL pg_hba.conf file
  • AWS Elastic Beanstalk Docker PHP application
  • Running Docker as non-root user
  • class Tag(models.Model):
        name = models.CharField(max_length=100)
    class QueryStringTab(models.Model):
        tag = models.ForeignKey(Tag, related_name='querystringtab')
        querystring = models.ForeignKey(QueryString, related_name='querystringtab')
    class QueryString(BaseObject): 
        Query string holds an SQL statement and query properties for execution
        server_id = models.IntegerField()
        schema = models.CharField(max_length=255, blank=True)
        query = models.CharField(max_length=60000) 
        variables = models.TextField(blank=True)
        created_by = models.ForeignKey(User, related_name='queries_created')
        updated_by = models.ForeignKey(User, related_name='queries_last_edited')
        created_at = models.DateTimeField(auto_now_add=True)
        updated_at = models.DateTimeField()
        touched_by = models.CharField(max_length=1000)
        config = models.TextField(blank=True)
        runs_started = models.IntegerField(default=0)
        runs_completed = models.IntegerField(default=0)
        runs_completed_duration = models.IntegerField(default=0) # total number of seconds spent running this query to completion
        formats = "pretty_html html json prettyjson csv excel tableau".split()

    Noteworthy points…

    1) It is recognizing the Tag model just fine.

    2) Could it have something to do with the fact that QueryString is a BaseObject

    3) It is successfully creating the Tag table in the mysql database

    Can anyone find anything obvious that I am doing wrong?

  • Change the owner of a file in a running Docker container with an attached volume in Windows
  • Remote debugging running process inside docker container
  • How to bind a shared directory from container to host in Docker
  • How can I redirect a single port in a docker container to the container's host?
  • wrapping DB in docker image
  • database docker container design
  • One Solution collect form web for “Django models foreign key not recognizing 'QueryString' BaseObject”

    The declaration of QueryStringTab is before the one for QueryStringTab; so when Python evaluates the first, it has not yet seen any definition for the second and therefore reports a NameError.

    Django allows you to use a string target than a class object in cases like this:

    querystring = models.ForeignKey('QueryString', related_name='querystringtab')

    Or, you could simply move the definition of QueryStringTab to the end.

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.