ModuleNotFoundError: No module named 'book' django - python

First I create a new app book and create a model class book, then I messed up with that. I delete that app and create another app and run python3 manage.py runserver.
Then I get this error:
.
I don't add anything in the new app. What can I do now? Is there anything more I want to specify?
project directory and installed apps
enter image description here

after creating any app in django, you need to add it's name to the INSTALLED_APPS inside the settings.py file.
Also make sure to run makemigrations before running migrate command like below:
python manage.py makemigrations
for a specific app:
python manage.py makemigrations <app name>

Related

"manage.py startapp" doesn't create db.sqlite3

I'm following an online tutorial in order to learn Django/Python. I'm using PyCharm Community Edition as my IDE. On Windows 10.
When I run python manage.py startapp myapp at the (venv) prompt in terminal window , no error is shown, and \myapp folder is created with the expected content. However, the file db.sqlite3 is not created, and I can't follow through the rest of the tutorial.
What might be going wrong here?
Thank you very much.
when you start a new django app no database must created.
you can run command
python manage.py migrate
to generate database for your project.
default database is sqlite and stored in file named db.sqlite3
Command python manage.py startapp myapp does not create db.sqlite3.
Run:
python manage.py makemigrations
python manage.py migrate
It will automatically create one if not present.

Cannot start django app

I am a newbie at Django and everytime I try to run (myvenv) C:\Users\lenovo> python manage.py startapp blogit gives me the error:
CommandError: 'blog' conflicts with the name of an existing Python module and cannot be used as an app name. Please try another name.
Am I doing something wrong?
You can't run the command from a directory above your project.
you should do this:
cd projectName
python manage.py startapp blog

Django: Migrations not recognizing cloudinary?

Hey I am trying to replace storing files to using cloudinary in my django app. I add
image2 = CloudinaryField('image')
to my models.py and run make migrations but nothing happens. Then when I run the server I get the error that image2 column does not exist. anyonee know what is gong on?
The following steps should work for you:
Adding image2 = CloudinaryField('image') to your models.py file
./manage.py makemigrations myapp
./manage.py migrate myapp
Make sure you run the migrate instruction as well
`

Django 1.7 - App 'your_app_name' does not have migrations

I am trying to upgrade from Django 1.6.7 to Django 1.7.1, so I have been trying to migrate my app.
I have followed the django docs here.
I deleted the south from my installed apps.
In the migration directory, I delete the numbered migration files and the .pyc files but I kept the directory & __ init__.py file.
I then run :
python manage.py makemigrations your_app_name
I receive the following confirmation message:
Migrations for 'your_app_name':
0001_initial.py:
- Create model UserProfile
Next I run:
python manage.py migrate your_app_name
I received the following error:
CommandError: App 'your_app_name' does not have migrations (you cannot selectively sync unmigrated apps)
As per the docs, I also ran:
python manage.py migrate --fake your_app_name
I received the same error message:
CommandError: App 'your_app_name' does not have migrations (you cannot selectively sync unmigrated apps)
Can anyone shed some light on why this will not work for me?
I noticed that only those apps that actually contain a migrations folder that contain a file __init__.py are recognized by migrations. IE having only models.py in your app is not enough.
If you have a single app, running migrate without specifying the app or migration may work.
If so, the first thing to check is that your app name matched that specified in your settings.py under INSTALLED_APPS.
As pointed out in the comments, app names can be in the form [parent_app].[app_name]. In this case, migrate needs [app_name] only.
Your app must contain a models.py file (even emtpy).
Source: https://groups.google.com/forum/#!msg/django-users/bsTZEmxgDJM/wH0p3xinBWIJ
Just to mention another possible reason:
In my Django app i added the correct migrations and installed the app with pip and got the same error.
What i was missing is a correct MANIFEST.in file
Also the parameter include_package_data in setup() from the setup.py file was not set to True.

NoMigrations exception for django.contrib.x has no migrations

I am trying to migrate a model that has nothing to do with this and as soon as I do migrate it gives me this error:
NoMigrations: Application '<module 'django.contrib.comments' from C:\Python27\lib\site-packages\django\contrib\comments\__init__.pyc' has no migrations.
I have tried deleting migrations folder and deleting databases but keeps coming up.
It can be that you have another app named as the last part of the module in this case 'comments' or you have an entry in the database table south_migrationhistory with app_name same as the module.
Found answer here Google Groups
i suggest if you can use django dumpdata , you will get a json file copy of your model.
$ python manage.py dumpdata <app-name> --indent=2
or create a folder to put the result in
$ python manage.py dumpdata <app-name> --indent=2 > [project]/[app]/[folder]/file-name.json
later you can use data upload to rebuild the original model.

Categories

Resources