makemigrations not able to find app within INSTALLED_APPS - python

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

Related

I keep getting no changes detected when migrating app in Django

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

error: App 'polls' could not be found. Is it in INSTALLED_APPS? *But polls is in INSTALLED_APPS in settings.py. I

I am trying to create the 'polls' part of my Django project/website and the tutorial (https://docs.djangoproject.com/en/1.8/intro/tutorial01/) says that before we 'activate' the models we have to include 'polls' in the INSTALLED_APPS library in settings.py. I did that, then I do--> $ python manage.py make migrations polls. This gives me the error--> App 'polls' could not be found. is it in INSTALLED_APPS?. What do I do from here?! I synced my database after I added polls, still doesn't work.
172-16-22-166:mysite manuelgomez$ cd
172-16-22-166:~ manuelgomez$ cd mysite
172-16-22-166:mysite manuelgomez$ ls
chocolate llama nuts story
db.sqlite3 manage.py polls urls.py
fts mysite settings.py
172-16-22-166:mysite manuelgomez$ python manage.py migrate
Operations to perform:
Apply all migrations: admin, contenttypes, auth, sessions
Running migrations:
No migrations to apply.
172-16-22-166:mysite manuelgomez$ python manage.py syncdb
Operations to perform:
Apply all migrations: admin, contenttypes, auth, sessions
Running migrations:
No migrations to apply.
172-16-22-166:mysite manuelgomez$ python manage.py makemigrations polls
App 'polls' could not be found. Is it in INSTALLED_APPS?
172-16-22-166:mysite manuelgomez$
In settings.py you will find INSTALLED_APPS and you must add the polls as shown below.
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'polls'
]
add setting like this
INSTALLED_APPS = (
...
'you_app_name',
)
a simple : python manage.py makemigrations do the trick for me and will detect your models and make migrations
Remove the app from comand. Example: python manage.py makemigrations
Did you check database?
You should find "your app" at 'app' column in "Django_migrations" table.
if not, you should type "python manage.py migrate" command, "DJANGO_MIGRATIONS" table is created.
(In case of using window and cmd, you should restart cmd.)
Good luck.

django listing files instead of showing home page

I'm not able to figure out what's going wrong. I'm using pycharm and bitnami django stack for developing my first web application.
Here is my directory structure:
project name: myapp
location: C:\Bitnami\djangostack-1.7.8-0\apache2\htdocs\myapp
Directory structure:
myapp
manage.py
app
admin.py
models.py
settings.py
tests.py
urls.py
views.py
wsgi.py
migrations
templates
home.html
my settings.py has following data:
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'app',
)
ROOT_URLCONF = 'app.urls'
TEMPLATE_DIRS = (
os.path.join(BASE_DIR, 'templates'),
)
my urls.py has following data:
from django.conf.urls import url
from . import views
urlpatterns = [
url(r'myapp/', views.homepage, name='home'),
]
my views.py has following data:
from django.http import HttpResponse
def homepage(request):
return HttpResponse("Hello, world!")
Now when I try to run:
http://localhost/myapp
It simply displays the list of files in the myapp directory
I'm not able to find why it is not executing from urls.py
If you want to get your app up and running with Apache, you will have to enable reverse-proxying.
To do this, you can try adding the following lines to /opt/bitnami/apache2/conf/httpd.conf, supposing that your application myapp is running at port 8000:
ProxyPass /myapp http://localhost:8000/myapp
ProxyPassReverse /myapp http://localhost:8000/myapp
To make sure that the mod_proxy module is enabled, please find the following lines and uncomment them:
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_connect_module modules/mod_proxy_connect.so
Finally, after saving the changes you can proceed to restart Apache:
/opt/bitnami/ctlscript.sh restart apache
You should now be able to access your application in: http://localhost/myapp
I'm able to run the project with the development server. In Pycharm, I went to Tools -> Run manage.py Task -> run server
And then executed the url:
http://localhost:8000/myapp/
But still trying to figure out why it is not running with apache in Bitnami stack

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.

Django: Error: Unknown command: 'makemigrations'

I am trying to follow the Django tutorial and I faced the following error when I enter python manage.py makemigrations polls
Unknown command: 'makemigrations'
Here's the link to the tutorial and I accomplished all the previous steps successfully and I am not sure what's going wrong now or how to fix it.
P.S.: I have already included "polls" in the INSTALLED_APPS!
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'polls',
'South',
)
Answer: I had to modify INSTALLED_APPS to :
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'polls',
)
and also used this command: python manage.py syncdb
Migrations were first added in version 1.7, officially released on September 2, 2014. You need to make sure your tutorial matches the version of Django you're working with. For instance, this version of the tutorial covers 1.9:
https://docs.djangoproject.com/en/1.9/intro/tutorial01/
Or, if you're using an older version of Django, you can change the "1.9" in that URL to whatever version you're on (back to 1.3). Or use the dropdown on the docs page to pick the version and search for "tutorial".
Find out what version of django you're running (thanks #BradyEmerson):
python -c "import django; print(django.get_version())"
If older than 1.8:
pip install --upgrade django
I was using version 1.9 and still getting this error. I had unapplied migrations and that was the root cause in my case. I ran 'python manage.py migrate' to apply them and it worked for me.
In django makemigration added after 1.7 so if you are using older version of Django then you have to change settings.py and add your application in installed app like
INSTALLED_APPS = (
'Demo',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
)
and then you can run command
python manage.py syncdb
You need to load the virtual environment before doing it.
Use below code for Linux/OSX:
source venv/bin/active
And the following code for Windows
source venv/Scripts/activate
I did following (for python version 3.6.4) to get this issue resolved:
install virtualenv
Activate virtualenv
Cheers
This worked for me: using ubuntu 20.04, Django 3.2
First after creating the model and addind to the setting, I did:
python manage.py makemigrations
I obtained the migration number here.
After that I did:
python manage.py sqlmigrate [NAME_OF_MODEL] [NUMBER_OF_THE_MIGRATION]
Finally:
python manage.py migrate
First time I add following piece of code into project_name\settings.py file.
`INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
#Django REST Framework
'rest_framework',
#Games application
'games.apps.GamesConfig',
]`
After save it, when run following code I got error.
`python manage.py makemigrations games`
Then I check the settings.py file I realize that there are two INSTALLED_APPS and second one has not followings. When I added these the code worked.
`#Django REST Framework
'rest_framework',
#Games application
'games.apps.GamesConfig',`

Categories

Resources