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'.
python manage.py?%(class)srelated 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.