Hey Guys,
iam pretty new to Django. Atm iam doing a tutorial on youtube to learn basic understandings.
In this tutorial i building my own project:
/mysite
db.sqlite3
manage.py
./mysite/
init.py
asgi.py
settings.py
urls.py
wsgi.py
./polls/
init.py
admin.py
apps.py
models.py
tests.py
urls.py
views.py
i added this to ./polls/models.py
from django.db import models
# Create your models here.
class User(models.Model):
name=models.CharField(max_length=128)
email=models.CharField(max_length=128)
Shell:
python manage.py makemigrations
No changes detected
python3 manage.py migrate
Operations to perform:
Apply all migrations: admin, auth, contenttypes, sessions
Running migrations:
No migrations to apply.
if iam checking db.sqlite3 there should be a tabel called usermodel_user but is not in there. pls help.
Like i said iam complete beginner. Pls dont get angry for a stupid noob question
Why is the sql not applied?
Personally, I recommend working through either the Official Django Tutorial or the Django Girls Tutorial. Itās hard to help you with a tutorial that Iām not familiar with, and canāt determine if itās accurate or appropriate.
Beyond that, unless youāre planning to completely replace the functionality of the built-in User
model, I wouldnāt name a model, User
. Iād pick a different name. If you need to add functionality to User
, see Customizing authentication in Django | Django documentation | Django. However, as a beginning user, I wouldnāt recommend that as a starting point either.
Regarding your migrations, see django-admin and manage.py | Django documentation | Django
Hey, iāve already did the Official Django Tutorial. My polls app is working. So Iāam now playing around sql.
I did nothing special just added this simple lines to my polls ap in models.py
from django.db import models
# Create your models here.
class User(models.Model):
name=models.CharField(max_length=128)
email=models.CharField(max_length=128)
the question if i run:
python3 manage.py makemigrations
python3 manage.py migrate
nothing happens and the table will not appear in my sql file. Iāam feeling complete stuck atm .
Maybe you can look at this simple lines why it is not creating a table in my database?
The solution is documented here:
Hey,
thx for your answer but i have Problembs with the syntax. What is applabel in
django-admin makemigrations [app_label [app_label ...]]
?
I tried
django-admin makemigrations mysite
django-admin makemigrations polls
both gave me error output. Thx for your help.
django-admin makemigrations polls
Traceback (most recent call last):
File "/home/naseweis/.local/bin/django-admin", line 8, in <module>
sys.exit(execute_from_command_line())
File "/usr/local/lib/python3.9/site-packages/django/core/management/__init__.py
", line 419, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python3.9/site-packages/django/core/management/__init__.py
", line 413, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/local/lib/python3.9/site-packages/django/core/management/base.py", l
ine 354, in run_from_argv
self.execute(*args, **cmd_options)
File "/usr/local/lib/python3.9/site-packages/django/core/management/base.py", l
ine 393, in execute
self.check()
File "/usr/local/lib/python3.9/site-packages/django/core/management/base.py", l
ine 419, in check
all_issues = checks.run_checks(
File "/usr/local/lib/python3.9/site-packages/django/core/checks/registry.py", l
ine 76, in run_checks
new_errors = check(app_configs=app_configs, databases=databases)
File "/usr/local/lib/python3.9/site-packages/django/core/checks/model_checks.py
", line 18, in check_all_models
models = apps.get_models()
File "/usr/local/lib/python3.9/site-packages/django/apps/registry.py", line 179
, in get_models
self.check_models_ready()
File "/usr/local/lib/python3.9/site-packages/django/apps/registry.py", line 141
, in check_models_ready
raise AppRegistryNotReady("Models aren't loaded yet.")
django.core.exceptions.AppRegistryNotReady: Models aren't loaded yet.
Since you are running this in the context of an āactive projectā, you would use the manage.py
command, not django-admin
. (Thatās documented at the top of that page.) You can use django-admin
, but you would need to manually set the evironment. (manage.py
does that for you.)
ok i tried:
python3 manage.py makemigrations polls
No installed app with label āpollsā.
my polls application running on the internet http://naseweis.pythonanywhere.com/polls/
When Iam running:
python3 manage.py makemigrations
python3 manage.py migrate
it running through but it will not create the table in the sql file
What does your installed_apps
setting look like in your settings.py
file?
What are the contents of your polls/apps.py
file?
installed_apps looks like this
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
]
Content of polls/app.py:
from django.apps import AppConfig
class PollsConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'polls'
Thanks a lot for your help
You need to include your polls app into the INSTALLED_APPS.
See Applications | Django documentation | Django
I added that to my settings.py, but now i have errors on python3 manage.py check
ImportError: Module 'polls.apps' does not contain a 'PollsAppConfig' class. Choic
es are: 'PollsConfig'.
my /polls/apps.py look like this:
from django.apps import AppConfig
class PollsConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'polls'
this is the whole error code from manage.py check:
python3 manage.py check
Traceback (most recent call last):
File "/home/naseweis/django_projects/mysite/manage.py", line 22, in <module>
main()
File "/home/naseweis/django_projects/mysite/manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "/usr/local/lib/python3.9/site-packages/django/core/management/__init__.py
", line 419, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python3.9/site-packages/django/core/management/__init__.py
", line 395, in execute
django.setup()
File "/usr/local/lib/python3.9/site-packages/django/__init__.py", line 24, in s
etup
apps.populate(settings.INSTALLED_APPS)
File "/usr/local/lib/python3.9/site-packages/django/apps/registry.py", line 91,
in populate
app_config = AppConfig.create(entry)
File "/usr/local/lib/python3.9/site-packages/django/apps/config.py", line 221,
in create
raise ImportError(msg)
ImportError: Module 'polls.apps' does not contain a 'PollsAppConfig' class. Choic
es are: 'PollsConfig'.
Thx for your help now my polls application migrate correctly and i can continue with my tutorial
Much Much THX
1 Like