I keep getting no changes detected when migrating app in Django - python

I am following this video tutorial to learn Django: https://www.youtube.com/watch?v=F5mRW0jo-U4&t=909s
I am at the "Your first app component" section where he creates an app and then migrates it. I have followed every one of his steps so far yet I keep getting the no changes detected error when I migrate the app
I have tried researching ways to fix this but it doesn't seem like there is any one right way to do it, it's more of a case by case basis. I've made sure my app is under the install_apps section in the settings. I've tried python manage.py makemigrations but that tells me there are no changes detected. I've tried "python manage.py makemigrations product" to be more specific but it tells me that App 'product' could not be found. Is it in INSTALLED_APPS?" even though it is in installed apps
currently this is my installed apps section:
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'product',

after migrate and makemigrations command put your app name
like this
python manage.py migrate product
python manage.py makemigrations product
my case it's working

You didn't add your app name in 'Installed_Apps' in settings.py. Add this first and then run again.

for a proper migrations with 'python manage.py makemigrations' make sure that after creating your model class you save them before you typing any console code very important

Related

operational error: no such table django Every Time I create models

I am using Django 2.0, Python
Every Time I am creating new Model when I do
python3 manage.py makemigrations
it shows no changes detected and on migrate no migrations to apply
Even I tried
python3 manage.py makemigrations home
shows
Migrations for 'home':
home/migrations/0001_initial.py
- Create model FAQ
- Create model Topic
and then on
python3 manage.py migrate home
It still shows
Operations to perform:
Apply all migrations: home
Running migrations:
No migrations to apply.
and when I try to open that table in admin.
it shows
OperationalError at /admin/home/faq/
no such table: home_faq
however it'd worked when I'd deleted migrations and database and re migrated everything.
But I can't delete everything Every Time.
my models.py
from django.db import models
# Create your models here.
class Topic(models.Model):
topic_title = models.CharField(max_length=200,unique=True)
topic_discription = models.TextField()
no_of_posts = models.IntegerField()
def __str__(self):
return self.topic_title
class FAQ(models.Model):
question = models.CharField(max_length=800,unique=True)
answer = models.TextField()
timestamp = models.DateTimeField(auto_now_add=True,auto_now=False)
author = models.CharField(max_length=100)
author_info = models.TextField()
def __str__(self):
return self.question
I've registered it on admin.py
from django.contrib import admin
from .models import Topic,FAQ
# Register your models here.
admin.site.register(Topic)
admin.site.register(FAQ)
EDIT #1:
Okay now I cleared all migrations and db.sqlite3 and ran
# python3 manage.py makemigrations
No changes detected
# python3 manage.py makemigrations home
Migrations for 'home':
home/migrations/0001_initial.py
- Create model FAQ
- Create model Topic
# python3 manage.py migrate home
Operations to perform:
Apply all migrations: home
Running migrations:
Applying home.0001_initial... OK
It does work but I rebuild the database for that.
Because It's not in production yet so its okay but It may become big problem later.
thing to notice is on
python3 manage.py makemigrations
It shows
No changes detected
but created migrations when
python3 manage.py makemigrations home
and have friendly response on
python3 manage.py migrate home
So even if there is any way to force rebuild the model in db then could do.( python3 manage.py force migrate )
^ Could be possible solution. if there exist force
EDIT #2:
Installed Apps:
INSTALLED_APPS = [
'home.apps.HomeConfig',
'UserProfile.apps.UserprofileConfig',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
]

django-newsletter - no runjobs in manage.py commands?

Hi I'm reading the docs for using django-newsletter.
And it says to call the following admin command to actually send the emails:
./manage.py runjob submit
In other parts of the docs it says runjobs instead of runjob.
Anyways, I'm not seeing either runjob or runjobs in the list of commands ./manage.py help, even though the 'newsletter' app is in installed_apps and I can access it in the admin.
What am I missing?
I was missing django_extensions in INSTALLED_APPS. The actual requirements for django-newsletter in INSTALLED_APPS are:
INSTALLED_APPS = (
...
'sorl.thumbnail',
'django_extensions',
'newsletter',
...
)

makemigrations not able to find app within INSTALLED_APPS

I am trying to port an existing django 1.4 project to django 1.7
Here is my tree structure before I ported the project to django 1.7
Project
- MainApp
- manage.py
- settings.py
- another_sub_app
- another_sub_app2
While porting the project I had to move manage.py and sub_apps one level up.
Project
- another_sub_app
- another_sub_app2
- manage.py
- MainApp
- settings.py
I used "South" for database migrations and had to use "python manage.py schemamigration " to make migrations. Now (after porting) I will be using "python manage.py makemigrations " to migrate app specific model changes.
However, while running "python manage.py makemigrations " I am getting:
App 'app_name' could not be found. Is it in INSTALLED_APPS?
I have the app under INSTALLED_APPS and due to the structural changes I made I also tried including . inside INSTALLED_APPS. But this shows the same error again.
My question is has anyone tried porting a project to django 1.7 and has had similar issue?
I haven't tried porting a project to django 1.7. However, I use django 1.7 and your settings.py should look like this
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.sites',
'your_app_name', #In your case, MainApp
'your_app_name', #In your case, another_sub_app
'your_app_name', #In your case, another_sub_app2
)
And the tree structure is
Project
- Project
- settings.py
- MainApp
- another_sub_app
- another_sub_app2
- manage.py

"python manage.py syncdb" not creating tables

I first ran
python manage.py syncdb
and it created the database and tables for me, then I tried to add more apps, and here's what I did:
create apps by
python manage.py startapp newapp
Then I added 'newapp' to INSTALLED_APPS in setting.py:
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'newapp',
)
At last I ran syncdb:
python manage.py syncdb
and here's the result I get:
Creating tables ...
Installing custom SQL ...
Installing indexes ...
Installed 0 object(s) from 0 fixture(s)
I checked my db and there is no table named newapp, no table's name including newapp.
I also ran into this issue, and was able to get around it by removing the migrations folder inside my app. Somehow that had already gotten created and was tricking syncdb into thinking that it was fully migrated already, but those migration scripts didn't actually do anything useful. Obviously don't try this if you actually have migrations you want to save, but I was working with a brand new app and models.
If you run:
python manage.py inspectdb > somefile.txt
You can get quickly check out if your database structure is matching your django models.
I tried most of the ideas above:
making sure the models.py is imported (verified that the module executed during a makemigrate),
deleting the migrations folder
setting managed = True (this is default anyways),
used the python manage.py inspectdb (which correctly dumped the table, if I had created it manually).
The key was simply to run a makemigrations on the app separately:
python manage.py makemigrations <app_name>
as part of performing the makemigrations step. Then you do
python manage.py migrate
afterwards as usual.
(applies to Django 1.10, using Postgres 9.5).
Django documentation
Credit, related post
i got same problem, but i didn't have any "migration" folder. I solved it like below.
I just added app_label with the model code,
class MyModel(models.Model):
...
class Meta:
managed = True # add this
app_label = 'myapp' # & this
Also, make sure it is discoverable by referencing it in myapp/models/__init__.py
from model_file.py import MyModel
You should be using this command
python manage.py migrate
where you were runing syncdb from the location where manage.py resides
I was having the same problem and noticed that it had created a db.sqlite3 file that didn't seem empty:
$ ls -l
-rw-r--r-- 1 sauron staff 122880 Jul 31 01:22 db.sqlite3
I tried running sqlite again using the filename as an argument and that worked:
$ sqlite3 db.sqlite3
SQLite version 3.7.13 2012-07-17 17:46:21
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> .schema
CREATE TABLE "auth_group" (
"id" integer NOT NULL PRIMARY KEY,
"name" varchar(80) NOT NULL UNIQUE
);
... many rows ...

PyCharm discovering new core Django (rather than app) manage.py tasks?

I'm hoping to use a newer Django (1.7.dev) inside PyCharm 2.7.3... so it's the only Django version installed in my project's virtualenv.
But, the "Tools" -> "Run manage.py task" list isn't discovering the new commands included in Django itself, like migrate or makemigrations. (Based on prior experience with apps like South, I'd hoped all available tasks would be auto-discovered.)
Is there a way to help PyCharm 2.7.3 discover and use these new options?
the "Tools" -> "Run manage.py task" doesn't see the makemigration or migrate argument.
You can run manage.py with right click on manage.py file in you project.
with this output:
*
*Usage: manage.py subcommand [options] [args]
Options:
-v VERBOSITY, --verbosity=VERBOSITY
Verbosity level; 0=minimal output, 1=normal output,
2=verbose output, 3=very verbose output
--settings=SETTINGS The Python path to a settings module, e.g.
"myproject.settings.main". If this isn't provided, the
DJANGO_SETTINGS_MODULE environment variable will be
used.
--pythonpath=PYTHONPATH
A directory to add to the Python path, e.g.
"/home/djangoprojects/myproject".
--traceback Raise on exception
--no-color Don't colorize the command output.
--version show program's version number and exit
-h, --help show this help message and exit
Type 'manage.py help <subcommand>' for help on a specific subcommand.
Available subcommands:
[auth]
changepassword
createsuperuser
[django]
check
compilemessages
createcachetable
dbshell
diffsettings
dumpdata
flush
inspectdb
loaddata
makemessages
makemigrations
migrate
runfcgi
shell
sql
sqlall
sqlclear
sqlcustom
sqldropindexes
sqlflush
sqlindexes
sqlinitialdata
sqlmigrate
sqlsequencereset
squashmigrations
startapp
startproject
syncdb
test
testserver
validate
[sessions]
clearsessions
[staticfiles]
collectstatic
findstatic
runserver*
*
As you can see "makemigrations" and "migrate" are in the available subcommands for django
So you have to "Run" - > "Edit Configurations" and add "makemigrations" or "migrate" in the script parameters
Now run the script and it works
This is most likely because of how you have added apps in your INSTALLED_APPS tuple. So if it's something like this:
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
# Uncomment the next line to enable the admin:
'django.contrib.admin',
# Third Party apps -------------------------------------->
'south',
'django_extensions',
'dajaxice',
'dajax',
# My apps ----------------------------------------------->
'blog',
)
Then there should be no problem, and you should be able to find the commands you're looking for, if not, then you have a bug. However, if you have arranged things to be like so:
DJANGO_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles')
THIRD_PARTY_APPS = (
'south',
'django_extensions',
'dajaxice',
'dajax',
)
MY_APPS = ('blog', )
INSTALLED_APPS = DJANGO_APPS + THIRD_PARTY_APPS + MY_APPS
Then you have a problem, with 2.7 since PyCharm cannot understand this. So, my suggestion is that you make the tuple the way I showed you to begin with.

Categories

Resources