I have models.py in a Django app that has a few models that I have the corresponding tables for in MySQL, and others that I do not.
How do I get Django to create the tables for the models that don't have them?
I tried makemigrations and migrate, but they were not delivered.
But then again, when running tests under vcc_merged/cards_browser django.db.utils.ProgrammingError: (1146, "Table 'test_vcc.polls_choice' doesn't exist")
What am I doing wrong?
I am using Django 1.11.7, Python 3.6.3 on MySQL 5.7
apps.py for browser app:
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.apps import AppConfig
class BrowserConfig(AppConfig):
name = 'browser'
INSTALLED_APPS = [
'vcc_merged',
'vcc_merged.cards_browser',
'browser',
'django.contrib.sites',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
]
Try with
Python manage.py makemigrations
Than
Python manage.py migrate
It will work for you.
Related
i want to activate my models in my files, my code in terminal:
(env) PS C:\Users\MadYar\Desktop\code.py\learning_log> python manage.py makemigrations learning_logs
error:
No changes detected in app 'learning_logs'
im using django to make a web application and i add models in my settings.py like that:
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'learning_logs'
]
i dont know why it sais no changes detected in app 'learning_logs'
add empty __init__.py in learning_logs folder.
check if you have any models.py in learning_logs folder.
add some models, which inherited from django.models.Model:
from django import models
class MyModel(models.Model):
myfield = models.Charfield(max_length=255)
call python manage.py makemigrations learning_logs
if you see No changes detected in app 'learning_logs' again, try to read the tutorial, especially this part: https://docs.djangoproject.com/en/4.0/intro/tutorial02/
app/models:
from django.db import models
# Create your models here.
class Blogpost(models.Model):
topic = models.TextField(null=True)
descrip = models.TextField()
fd = models.CharField(max_length=150)
->I installed app already
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'website.apps.SbuiltConfig',
'rest_framework',
]
->I Register models already
from django.contrib import admin
from models import Blogpost, Blog, testblog
# Register your models here.
admin.site.register(Blogpost)
but it's still no change detected
enter image description here
You should mention your app/folder name in the INSTALLED_APPS list.
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'website.apps.SbuiltConfig',
'rest_framework',
# If your app's root folder name is Blogpost
'Blogpost',
# Or if your app's folder name is website
'website',
]
then after saving your settings.py, in terminal/shell:
python manage.py makemigrations
python manage.py migrate
you can also mention your app's name explicitly in command:
python manage.py makemigrations Blogpost
python manage.py migrate
if your app's name is website then:
python manage.py makemigrations website
python manage.py migrate
I ran the code settings.py and went to INSTALLED APPS and added learning_logs:
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'learning_logs',
Then in the terminal I ran 'python manage.py makemigrations learning_logs'
However it results in 'No changes detected in app 'learning_logs'
Note that I read some other articles and got no good answer
Also note that the end bracket is supposed to be in the dictionary
You can try this:
Add __init__.py file into the app folder.
Make sure you have some models classes created in models.py file in the app
Please check your model definition and make sure that it inherits from django models.Model!
from django.db import models
class MyCustomModel(models.Model):
...
I'm using Django and I have an schema like
mainapp
|---mainapp
| |---migrations.py
| |---models/
|---app2
|---migrations/
|---models/
But, when I execute:
python manage.py migrate it is generationg the tables of mainapp/models, but no the app2/models and app2/migrations either.
How can execute those migrations?
first of all try
python manage.py makemigrations
for a specific app
python manage.py makemigrations appname
this will migrate all the apps
then
python manage.py migrate
hope it helps
Make sure you have added the app in the installed apps.
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'mainapp',
'app2',
#......,
#......,
]
Then create migrations
using python mananage.py makemigrations and migrate with python manange.py migrate
I have a project named HubHub that contains 2 apps named DrHub and AgencyHub,when changing models syncdb doesn't change them and I tried to use south :
in settings.py:
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'grappelli',
'django.contrib.admin',
'south',
'AgencyHub',
'DrHub',
)
I ran the first command to config first migration based on this tutorial: http://south.aeracode.org/docs/tutorial/part1.html
python manage.py schemamigration DrHub --initial
and the second command:
python manage.py migrate DrHub
but this command cause this error:
table "model_name" already exist
"model_name" is the name of first model of models.py in DrHub
If you found any solution then post answer.
thanks in advance
It`s because initial migration will create all tables in database for you. And you have an existing database with existing tables. You can either wipe you database and then do a migrate or you need to use a --fake option in migrate. Docs here
python manage.py migrate DrHub --fake
Please remove the database table and try to create sync db.