0

Here is the stack trace i get when i run any manage.py commands

    Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/Library/Python/2.7/site-packages/django/core/management/__init__.py", line 338, in execute_from_command_line
    utility.execute()
  File "/Library/Python/2.7/site-packages/django/core/management/__init__.py", line 312, in execute
    django.setup()
  File "/Library/Python/2.7/site-packages/django/__init__.py", line 18, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/Library/Python/2.7/site-packages/django/apps/registry.py", line 108, in populate
    app_config.import_models(all_models)
  File "/Library/Python/2.7/site-packages/django/apps/config.py", line 198, in import_models
    self.models_module = import_module(models_module_name)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
  File "/Users/krishna/Documents/irrigationwebserver/webserver/irrigationservice/models.py", line 61, in <module>
    class IrrigationSession(models.Model):
  File "/Library/Python/2.7/site-packages/django/db/models/base.py", line 189, in __new__
    new_class.add_to_class(obj_name, obj)
  File "/Library/Python/2.7/site-packages/django/db/models/base.py", line 324, in add_to_class
    value.contribute_to_class(cls, name)
  File "/Library/Python/2.7/site-packages/django/db/models/fields/related.py", line 1783, in contribute_to_class
    super(ForeignObject, self).contribute_to_class(cls, name, virtual_only=virtual_only)
  File "/Library/Python/2.7/site-packages/django/db/models/fields/related.py", line 305, in contribute_to_class
    'app_label': cls._meta.app_label.lower()
ValueError: incomplete format

Here is the code in models.py and settings.py, those are the only places where I modified the django app.

models.py

    from django.db import models
from django.conf import settings
from django.contrib.auth.models import User, AbstractUser
from model_utils.fields import StatusField, MonitorField
from model_utils import Choices, FieldTracker
from jsonfield import JSONField
from django.utils.translation import gettext as _

class LastRequestStorable(models.Model):
    last_service_request = JSONField()
    req_tracker = FieldTracker()

    class Meta:
        abstract = True

class MapPointable(models.Model):
    loc_latitude = models.FloatField()
    loca_longtitude = models.FloatField()

    class Meta:
        abstract = True

class FarmStateble(models.Model):
    STATES = Choices((0, 'SLEEPING', _('Sleeping')), (1, 'SENSING', _('Sensing')), (2, 'WATERING', _('Watering')))
    state = StatusField(choices_name = 'STATES')
    state_tracker = FieldTracker(fields=['state'])

    class Meta:
        abstract = True

class Farmer(FarmStateble, MapPointable, LastRequestStorable, AbstractUser):
    last_irrigation_cycle = models.DateTimeField(auto_now_add=False, auto_now=False, null = True, blank=True)


class MoistureProfileDict(models.Model):
    name = models.CharField(max_length=30)

class MoistureKVPair(models.Model):
    profile = models.ForeignKey(MoistureProfileDict)
    sector_key = models.CharField(max_length=30)
    sector_value = models.DecimalField(max_digits=3, decimal_places=3, default=0)


class BotanicData(models.Model):
    soil_choices = Choices('LOAM', 'SILT', 'CLAY', 'SAND')
    soil_type = models.CharField(choices= soil_choices, blank=True, max_length=20)
    seed_choices = Choices('TOMATOE', 'POTATOE', 'CARROT', 'STRAWBERRY', 'CHICKEN')
    seed = models.CharField(choices=seed_choices, blank = True, max_length=15)
    root_depth = models.IntegerField(default=0)
    field_capacity = models.DecimalField(max_digits=3, decimal_places=3, default=0)
    perm_wilt_point = models.DecimalField(max_digits=3, decimal_places=3, default=0)
    max_depl = models.DecimalField(max_digits=3, decimal_places=3, default=0)


class Analytics(models.Model):
    power_used = models.DecimalField(max_digits=3, decimal_places=2, default=0)
    water_used = models.DecimalField(max_digits=3, decimal_places=2, default=0)
    water_saved = models.DecimalField(max_digits=3, decimal_places=2, default=0)


class IrrigationSession(models.Model):
    user = models.OneToOneField(settings.AUTH_USER_MODEL)
    botany = models.OneToOneField(BotanicData)
    analytics = models.OneToOneField(Analytics)
    sector1_moist_prof = models.OneToOneField(MoistureProfileDict, related_name="%(class)")
    sector2_moist_prof = models.OneToOneField(MoistureProfileDict, related_name="%(class)")
    sector3_moist_prof = models.OneToOneField(MoistureProfileDict, related_name="%(class)")

settings.py

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import os

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.8/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '=%m-!gjz88m15lo^buqxuhqv7pv0ih_9)x+v#_dxub#ye&jbry'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = []


# Application definition

INSTALLED_APPS = (
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'irrigationservice',
)

AUTH_USER_MODEL = 'irrigationservice.Farmer'

MIDDLEWARE_CLASSES = (
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
    'django.middleware.security.SecurityMiddleware',
)

ROOT_URLCONF = 'webserver.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

WSGI_APPLICATION = 'webserver.wsgi.application'


# Database
# https://docs.djangoproject.com/en/1.8/ref/settings/#databases

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
    }
}


# Internationalization
# https://docs.djangoproject.com/en/1.8/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.8/howto/static-files/

STATIC_URL = '/static/'

I've tried to google the error or search stack overflow for some answers but I can't see what I did wrong.

EDIT 1: After taking suggestions on changing the related name to be different for each one I've changed them to sess_1 sess_2 and sess_3 respectivly. but I now get this error which I was trying to avoid.

python manage.py makemigrations                                                            ✗ krish/modelsdefintion ☁

SystemCheckError: System check identified some issues:

ERRORS:
irrigationservice.IrrigationSession.sector2_moist_prof: (fields.E304) Reverse accessor for 'IrrigationSession.sector2_moist_prof' clashes with reverse accessor for 'IrrigationSession.sector3_moist_prof'.
    HINT: Add or change a related_name argument to the definition for 'IrrigationSession.sector2_moist_prof' or 'IrrigationSession.sector3_moist_prof'.
irrigationservice.IrrigationSession.sector2_moist_prof: (fields.E305) Reverse query name for 'IrrigationSession.sector2_moist_prof' clashes with reverse query name for 'IrrigationSession.sector3_moist_prof'.
    HINT: Add or change a related_name argument to the definition for 'IrrigationSession.sector2_moist_prof' or 'IrrigationSession.sector3_moist_prof'.
irrigationservice.IrrigationSession.sector3_moist_prof: (fields.E304) Reverse accessor for 'IrrigationSession.sector3_moist_prof' clashes with reverse accessor for 'IrrigationSession.sector2_moist_prof'.
    HINT: Add or change a related_name argument to the definition for 'IrrigationSession.sector3_moist_prof' or 'IrrigationSession.sector2_moist_prof'.
irrigationservice.IrrigationSession.sector3_moist_prof: (fields.E305) Reverse query name for 'IrrigationSession.sector3_moist_prof' clashes with reverse query name for 'IrrigationSession.sector2_moist_prof'.
    HINT: Add or change a related_name argument to the definition for 'IrrigationSession.sector3_moist_prof' or 'IrrigationSession.sector2_moist_prof'.

EDIT 2: using %(class)s as related name

change in models.py

    sector1_moist_prof = models.OneToOneField(MoistureProfileDict, related_name="%(class)s")
sector2_moist_prof = models.OneToOneField(MoistureProfileDict, related_name="%(class)s")
sector3_moist_prof = models.OneToOneField(MoistureProfileDict, related_name="%(class)s")

ERRORS: irrigationservice.IrrigationSession.sector1_moist_prof: (fields.E304) Reverse accessor for 'IrrigationSession.sector1_moist_prof' clashes with reverse accessor for 'IrrigationSession.sector2_moist_prof'.

    HINT: Add or change a related_name argument to the definition for 'IrrigationSession.sector1_moist_prof' or 'IrrigationSession.sector2_moist_prof'.
irrigationservice.IrrigationSession.sector1_moist_prof: (fields.E304) Reverse accessor for 'IrrigationSession.sector1_moist_prof' clashes with reverse accessor for 'IrrigationSession.sector3_moist_prof'.
    HINT: Add or change a related_name argument to the definition for 'IrrigationSession.sector1_moist_prof' or 'IrrigationSession.sector3_moist_prof'.
irrigationservice.IrrigationSession.sector1_moist_prof: (fields.E305) Reverse query name for 'IrrigationSession.sector1_moist_prof' clashes with reverse query name for 'IrrigationSession.sector2_moist_prof'.
    HINT: Add or change a related_name argument to the definition for 'IrrigationSession.sector1_moist_prof' or 'IrrigationSession.sector2_moist_prof'.
irrigationservice.IrrigationSession.sector1_moist_prof: (fields.E305) Reverse query name for 'IrrigationSession.sector1_moist_prof' clashes with reverse query name for 'IrrigationSession.sector3_moist_prof'.
    HINT: Add or change a related_name argument to the definition for 'IrrigationSession.sector1_moist_prof' or 'IrrigationSession.sector3_moist_prof'.
irrigationservice.IrrigationSession.sector2_moist_prof: (fields.E304) Reverse accessor for 'IrrigationSession.sector2_moist_prof' clashes with reverse accessor for 'IrrigationSession.sector1_moist_prof'.
    HINT: Add or change a related_name argument to the definition for 'IrrigationSession.sector2_moist_prof' or 'IrrigationSession.sector1_moist_prof'.
irrigationservice.IrrigationSession.sector2_moist_prof: (fields.E304) Reverse accessor for 'IrrigationSession.sector2_moist_prof' clashes with reverse accessor for 'IrrigationSession.sector3_moist_prof'.
    HINT: Add or change a related_name argument to the definition for 'IrrigationSession.sector2_moist_prof' or 'IrrigationSession.sector3_moist_prof'.
irrigationservice.IrrigationSession.sector2_moist_prof: (fields.E305) Reverse query name for 'IrrigationSession.sector2_moist_prof' clashes with reverse query name for 'IrrigationSession.sector1_moist_prof'.
    HINT: Add or change a related_name argument to the definition for 'IrrigationSession.sector2_moist_prof' or 'IrrigationSession.sector1_moist_prof'.
irrigationservice.IrrigationSession.sector2_moist_prof: (fields.E305) Reverse query name for 'IrrigationSession.sector2_moist_prof' clashes with reverse query name for 'IrrigationSession.sector3_moist_prof'.
    HINT: Add or change a related_name argument to the definition for 'IrrigationSession.sector2_moist_prof' or 'IrrigationSession.sector3_moist_prof'.
irrigationservice.IrrigationSession.sector3_moist_prof: (fields.E304) Reverse accessor for 'IrrigationSession.sector3_moist_prof' clashes with reverse accessor for 'IrrigationSession.sector1_moist_prof'.
    HINT: Add or change a related_name argument to the definition for 'IrrigationSession.sector3_moist_prof' or 'IrrigationSession.sector1_moist_prof'.
irrigationservice.IrrigationSession.sector3_moist_prof: (fields.E304) Reverse accessor for 'IrrigationSession.sector3_moist_prof' clashes with reverse accessor for 'IrrigationSession.sector2_moist_prof'.
    HINT: Add or change a related_name argument to the definition for 'IrrigationSession.sector3_moist_prof' or 'IrrigationSession.sector2_moist_prof'.
irrigationservice.IrrigationSession.sector3_moist_prof: (fields.E305) Reverse query name for 'IrrigationSession.sector3_moist_prof' clashes with reverse query name for 'IrrigationSession.sector1_moist_prof'.
    HINT: Add or change a related_name argument to the definition for 'IrrigationSession.sector3_moist_prof' or 'IrrigationSession.sector1_moist_prof'.
irrigationservice.IrrigationSession.sector3_moist_prof: (fields.E305) Reverse query name for 'IrrigationSession.sector3_moist_prof' clashes with reverse query name for 'IrrigationSession.sector2_moist_prof'.
    HINT: Add or change a related_name argument to the definition for 'IrrigationSession.sector3_moist_prof' or 'IrrigationSession.sector2_moist_prof'.
7
  • 1
    what do you try to do with python manage.py? Commented Nov 15, 2015 at 21:01
  • @pythad runserver, migrate, shell, all the same error Commented Nov 15, 2015 at 21:12
  • Your question has now changed into another question; this error is different from your original error. Commented Nov 15, 2015 at 22:54
  • I think the new error is pretty clear; it even gives you a hint what to do. Commented Nov 15, 2015 at 22:54
  • Can you please copy-paste your updated code? The %(class)s related name won't work (since that's identical for these fields), which suggests there's something else going on. Perhaps another typo, perhaps your migration file is now causing problems. If you're starting from scratch or you can afford it, clear/remove your database and migration file. Commented Nov 16, 2015 at 0:41

3 Answers 3

1

You're missing an 's' in the formatter for related_name: %(class)s.

Use

sector1_moist_prof = models.OneToOneField(MoistureProfileDict, \
related_name="%(class)s")

instead of

sector1_moist_prof = models.OneToOneField(MoistureProfileDict, \
related_name="%(class)")

(Ditto for the other fields.)

Sign up to request clarification or add additional context in comments.

4 Comments

Updated the question, this didn't do it :(
Instead of changing the related_name to sess_1, sess_2: do you get the same, original error you had when chaing %(class) to %(class)s? Because I think this solves your original issue, and you just stumbled upon another error.
yes I still got the same error in the format of "HINT: add or change the related_name argument to the definition of sector3_moist_prof... Which I assume is the same error when using sess1 and sess2
No, that means you got a different error than the error in your original question. I.e., both explicitly specifying a name like "sess_1" or using "%(class)s" solved your original error, but now you've run into a different (related) issue. Your original problem has been solved (essentially an oversight), and you should ask a new question regarding this error; in particular since all three answers here relate to your original problem, and now have little to nothing to do with your current problem.
1

From the traceback I can say that the problem is connected with related_names. I think you have to write %(class)s instead of %(class) in them

Comments

0

I can sugest you try to rewrite code:

sector1_moist_prof = models.OneToOneField(MoistureProfileDict, related_name="%(class)")
sector2_moist_prof = models.OneToOneField(MoistureProfileDict, related_name="%(class)")
sector3_moist_prof = models.OneToOneField(MoistureProfileDict, related_name="%(class)")

You are declared three one to one relations but give them all one reverse name, which is not definitely - if you will try to do reverse - django orm will not know what exacly relation to use

Try:

sector1_moist_prof = models.OneToOneField(MoistureProfileDict, related_name="sess_1")
sector2_moist_prof = models.OneToOneField(MoistureProfileDict, related_name="sess_2")
sector3_moist_prof = models.OneToOneField(MoistureProfileDict, related_name="sess_3")

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.