Reputation: 1673
I am new here in django
docker
.
I have created new model for django
app, I am working on docker
. When I am trying to use migrate command docker exec -ti 75ce87c91dc7 sh -c "python app/manage.py migrate"
, it says: No migrations to apply
. Here I have added my models.py file, do we need to import this models to anywhere else?
Folder Structure :
settings.py
"""
Django settings for trialriskincApi project.
Generated by 'django-admin startproject' using Django 2.2.7.
For more information on this file, see
https://docs.djangoproject.com/en/2.2/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/2.2/ref/settings/
"""
import os
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
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/2.2/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'xh86wu$_k@g46*+y9v_$2q^jnfg$uc44yh4+15nl2+2dx^$il%'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = ['0.0.0.0']
# Application definition
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'rest_framework',
'trialriskincApi',
]
MIDDLEWARE = [
'trialriskincApi.middleware.open_access_middleware',
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
ROOT_URLCONF = 'trialriskincApi.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 = 'trialriskincApi.wsgi.application'
# Database
# https://docs.djangoproject.com/en/2.2/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'trail_risk_inc_backend',
'USER': 'root',
'PASSWORD': '12345678',
'HOST': 'db', # Or an IP Address that your DB is hosted on
'PORT': '3306',
}
}
# Password validation
# https://docs.djangoproject.com/en/2.2/ref/settings/#auth-password-validators
AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]
# Internationalization
# https://docs.djangoproject.com/en/2.2/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/2.2/howto/static-files/
STATIC_URL = '/static/'
# Cors headers
CORS_ORIGIN_ALLOW_ALL = True
CORS_ALLOW_CREDENTIALS = False
CORS_ALLOW_HEADERS = [
'accept',
'accept-encoding',
'authorization',
'content-type',
'dnt',
'origin',
'user-agent',
'x-csrftoken',
'x-requested-with',
]
models.py
from django.conf import settings
from django.db import models
from django.utils import timezone
from django.contrib.auth.models import User
class Userprofile(models.Model) :
user = models.OneToOneField(User, on_delete=models.CASCADE)
type = models.SmallIntegerField(max_length=1)
created_date = models.DateTimeField(default=timezone.now)
updated_date = models.DateTimeField(blank=True, null=True)
def publish(self):
self.updated_date = timezone.now()
self.save()
def __str__(self):
return self.title
Upvotes: 0
Views: 432
Reputation: 2222
If you are getting No changes detected
that suggests that Django is not discovering your models.py
, given that you are using the project as your app as well, I am guessing you forgot to add your project name (which is the same as your app name) in your INSTALLED_APPS
.
e.g. in settings.py
INSTALLED_APPS = (
...
"trialriskincApi",
)
Upvotes: 1
Reputation: 357
To migrate a new model you have to run
python manage.py makemigrations <yourAppName>
And for Docker you do like this:
docker exec -ti 75ce87c91dc7 sh -c "python app/manage.py makemigrations <yourAppName>
Upvotes: 0