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…

  • Persistent easily-accessible storage in Docker
  • Consul and Tomcat in the same docker container
  • Docker pull fails with “Tag latest not found in repository” even when “latest” tag exists
  • Docker Compose Links not working with Host mode
  • Docker can't start MariaDB/MySQL during Docker build
  • What's the best way to synchronize a python script with a docker database container?
  • 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?

  • How to share a host directory between multiple docker container?
  • Android Emulator Couchbase Replication Database not found error
  • How to fix docker so that it stops messing with android studio from connecting to emulator in OSX
  • Using zookeeper for service discovery of mesos slaves running docker
  • Disable docker image being run as daemon (restart always policy)
  • What is a sparse block device at /dev/xvdf
  • 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.