Database & Migrations – Django Web Development with Python 8



Welcome to Part 8 of our Django web development with Python tutorial.

Remember how when you create a new app, the first thing you need to do is install it? Whenever you define new models, you want to migrate. If you are familiar with older versions of Django, the old syncdb command is deprecated. Nowadays, first you will do

python manage.py makemigrations

Text-based tutorial and sample code:

Nguồn: https://benjaminjcohen.com/

Xem thêm bài viết khác: https://benjaminjcohen.com/cong-nghe/

42 Comments

  1. hi,
    i have a little problem.
    how can you add fields in model runtime while website is running

  2. Bro i am getting indentation error I def

  3. I am getting following error any solution for this??

    from .models import PostForm

    ImportError: cannot import name 'PostForm' from 'blog.models'

  4. Sir,please help me when I load my blog page it just shows a blank space.In cmd I had no migration errors so please kindly help me

  5. hello

    I hava a Django (version 2.1.7) app on a windows which was set up with sqlite3 as the db, but it's going to production so I'm migrating the tables to oracle (OracleXE112)on the server, i don't care about the data just the tables so when I run python manage.py migrate
    I get ORA-2000 Error: missing ALWAYS keyword
    , django.db.migrations.exceptions.MigrationSchemaMissing: Unable to create the django_migrations table (ORA-02000: missing ALWAYS keyword)

    I'm new to django, what am i missing?

    please help me, and thank you.

  6. i know it would not generate as much views as much views since it would be the second time but would you mind just posting another tutorial for django but this time just one long video for the new version because alot has changed and it would help some whose debugging skills are not that great, that would be a big help to me and some few others, please consider it.

  7. No changes detected in app 'first'

  8. i am getting stuff on the blog page not sure what to do

  9. What changes required to DATABASE in setting.py to connect it with ms sql

  10. hey plz help me, I'm getting this error-> no such table: django_session <- i did nothing to any of these files. I just write django-admin startproject Mysite -> python manage.py createsuperuser and this time it is showing that error. what should I do in this?

  11. if you was to change the models.py file would you have to makemigrations again or is they an update

  12. Solved my "django.template.exceptions.TempalteDoesNotExist: blog/blog.html, blog/post_list.html" by taking the "/mysite/blog/template/" and the "blog/blog.html" (both folder and html file) and moved them under "/mysite/personal/templates". I tried to check my urls and settings according to the video instructions, but moving file seemed to work for me as it was giving error for not finding it in "personal/templates". I am using django version 2.1.2.

  13. hello do you know where i can possibly find the documentation on all the .objects.all() and related commnads plz??..i have a docs folder in my django project with txt docs and if and when i add docs or modify txt in the docs ..i dont see it update in my views in the web browser..anyone there?/,,thxz

  14. what if we dnt want to use the default sqlite. what if want to connect it to mysql db. how to do the co+nnectiona and migration?

  15. Hi sentdex your tutorials are awesome. Could help me in connecting to MySQL database

  16. Hello, I used inspectdb to get a modeld, then I copy and paste de models, but now I can't do makemigraitons:

    File "/home/xxx/xxx/ENV/lib/python3.5/site-packages/django/core/management/commands/makemigrations.py", line 211, in write_migration_files
    with open(writer.path, "w", encoding='utf-8') as fh:
    PermissionError: [Errno 13] Permission denied: '/home/xxx/xxxx/polls/migrations/0001_dimdddd_dimeeee_dimfffff_dimiiiiii_dimpppppppp_dimoooooo_dimssss_dimtttttt_mensa.py'

  17. You are too much, I really enjoyed every bit of the tutorials to this point

  18. For those encountering the TemplateDoesNotExist error when following the video instructions, I solved like this:
    path('', ListView.as_view(queryset=Post.objects.all().order_by("-date"), template_name='blog/blog.html')),
    template_name paramater needed to be inside the as_view() function signature, instead of the path() function like in previous urlpatterns. Just put queryset and template_name inside the same parenthesis.
    Hope this helps.

  19. sir , On pythonprogrmming.net we cant select particular video from respective tutorial, its very tedious to go through all videos to choose last video of tutorial, so fix that problem!!! thank you

  20. How do I fix the following:

    ModuleNotFoundError: No module named 'blog'. I check stackoverflow and none of the solutions work. Thanks.

  21. hey bro, you are awesome . I want to make a new page and add this with home page. How will i do this ???????????
    please help me bro

  22. My table will not line up. Blog is on the same line as Home. I used the fix from a couple videos back about flex column and nav-item. It worked until this video and I can't find what changes caused this.

  23. hi keep getting stuck trying to use postgresql on django. im using pycharmIDE.

  24. you are awesome!! Love from India

  25. can i use mongodb database?please reply

  26. "Treat me like a package" kinky

  27. i still have the error "template does not exist in the blog" , i cross checked all the steps but it had no mistake. what can i do to overcome the error

  28. I'm having trouble with this, as I'm getting this error on command(mac):

    Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x1041e9c80>
    Traceback (most recent call last):
    File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/urls/resolvers.py", line 407, in url_patterns
    iter(patterns)
    TypeError: 'module' object is not iterable

    During handling of the above exception, another exception occurred:

    Traceback (most recent call last):
    File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/utils/autoreload.py", line 227, in wrapper
    fn(*args, **kwargs)
    File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/core/management/commands/runserver.py", line 125, in inner_run
    self.check(display_num_errors=True)
    File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/core/management/base.py", line 359, in check
    include_deployment_checks=include_deployment_checks,
    File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/core/management/base.py", line 346, in _run_checks
    return checks.run_checks(**kwargs)
    File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/core/checks/registry.py", line 81, in run_checks
    new_errors = check(app_configs=app_configs)
    File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/core/checks/urls.py", line 16, in check_url_config
    return check_resolver(resolver)
    File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/core/checks/urls.py", line 26, in check_resolver
    return check_method()
    File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/urls/resolvers.py", line 255, in check
    warnings.extend(check_resolver(pattern))
    File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/core/checks/urls.py", line 26, in check_resolver
    return check_method()
    File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/urls/resolvers.py", line 254, in check
    for pattern in self.url_patterns:
    File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/utils/functional.py", line 35, in _get_
    res = instance.__dict__[self.name] = self.func(instance)
    File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/urls/resolvers.py", line 414, in url_patterns
    raise ImproperlyConfigured(msg.format(name=self.urlconf_name))
    django.core.exceptions.ImproperlyConfigured: The included URLconf '<module 'blog.urls' from '/Users/mingma/apps/mysite/blog/urls.py'>' does not appear to have any patterns in it. If you see valid patterns in the file then the issue is probably caused by a circular import.

  29. Very good videos.Please can you make some videos where we can display data from many to many relations and one to one in a view?It will help very much,thanks

  30. Fun fact: You didn't set up admin – Django does so out of the box apparently…I didn't set it up either but I also saw a login page.

  31. Django might decouple you from SQL, but oh boy, does it not decouple you from the DB…

  32. About the auto increment – ot's done by AutoField <- the field automatically increments according to available IDs, so none of the parameters is responsible (just to clarify as few comments were wrong about that).
    Btw, great videos! I can't wait to finish this one and Machine Learning series, both are amazing!

  33. @sentdex thanks for tutorial. I got a problem, maybe you can suggest something. I have a working Django project with different apps. I was changing something and deleted all db. Now when doing makemigrations and migrate, errors are coming out: appname_modelname relation doesn't exists. I tried to create those tables manually, but no solution. My db is PostGr.

  34. I don't know if somebody else had this error " UnicodeDecodeError: 'utf-8'…" but i'll like to share the solution because i pass the last 2 hours searching, the problem is on editor of html, the notepad++, we have to select the utf-8 on menu.
    Sorry if that is simple and obvious.

  35. my blog page is blank. how does header showing so much data

  36. The output from python manage.py makemigrations was only
    Migrations for 'blog':
    0001_initial.py
    – Create model Post

    So it is lacking -Create model Category

    Any idea why?

  37. i am a beginner , i think i am gonna try write a script that would go to your every video and click that like as a thank , wonder if its possible lol.

  38. loved the tutorials dude. Simple explanations for everything you did without all the jargon. This is awesome for people entering the python scene, me included.

    Thanks dude and good luck with your work

  39. Hey sentdex!!!! your videos are awesome!!!!!
    I am facing this error while i'm trying to run server (I' using Python 2.7).
    Error: not able to run manage.py runserver , <function wrapper at 0x0454D030>
    please help me.

  40. It's auto incrementing because it's an AutoField.

  41. I wish I could thumbs up twice, very good and detailed information.

Leave a Reply

Your email address will not be published. Required fields are marked *