Django Tutorial on database installation

Hello so today we are going to continue our Django project development. In today’s section we are going to setup database for our Django project. Those who are unaware about The Django project please refer this link. So first upon understand that some of us going to work with code for first time. So we will have to choose a simple yet powerful text editor to edit our source code.There are many options available in market. some prefer full functional text editor on the other side some prefer simple notepad. The choice is up to you. Choose any text editor you are comfortable with. If you have used any to text editor previously for python coding just stick with it as you become comfortable with it and it also became handy to use. Any text editor works fine with Django.

So now open setting.py file from the project we created earlier into your preferred text editor. you will find lots of code lines. just move to the line where database is declared as shown below it is on line 76

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME' : 'bookmarksdb'
    }
}

change ‘NAME’  to bookmarksdb where bookmarksdb is our database name. Now save the file and run following command to save changes into project

python manage.py makemigrations

it will look like this

django makemigration command

After this run another command as given below

python manage.py migrate

it will look like this

django migrate command

If you have entered the above command and everything is correct, status messages will scroll on the screen indicating that the tables are being created. As discussed before, Django comes with a lightweight web server for developing and testing applications. This server is pre-configured to work with Django, and more importantly, it restarts whenever you modify the code.

To start the server, run the following command:

python manage.py runserver

Next, open your browser, and navigate to 127.0.0.1:8000/. You should see a welcome message as in the image below

django runserver command

And output will be

django run project

Congratulations! we have installed and configured our first Django project. This project will be the basis on which we will build our bookmarking application in django. In next section we will start coding for our Django project. For now we are going to stop here. Till now if you face any problem regarding this post feel free to comment below we will try to resolve your problem regarding this as soon as possible.

Thank you..

Happy coding..