Django PostgreSQL Migration from SQLite

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello and welcome back to another django tutorial so in this tutorial i've created a simple application and now i'm ready to migrate from the default SQL like database to a Postgres database so I'm going to take you through the process of making a backup of the existing SQL like database then we're going to install the Postgres database onto our machine once we've done that we're going to install PG admin which is a simple graphical user interface to allow us to administrate our Postgres databases and then finally we're going to take that backup we made originally of our existing database and put it into a new Postgres database so once we finish doing all that we're then reconnect our django application to the new Postgres database and test to see if it's working so our first task then is to create a backup of the existing database and we can do that by typing in python manage dot py and then the dump data the right Chevron and then data dump jason so here we're going to make a backup of a database we're gonna call it data dump dot and jason and that's then going to appear inside of our actual application folder so at this point you're gonna need a django application and head over to the virtual environment if you're using the virtual environments and then just run the command so if I run the command you'll now find a new file called data dump jason inside of your project folder so here's all our data from the database which we can then import into the new Postgres database so the next step we need to now install prost quest database so heading over to google i just type in Postgres downloads and takes me then to the Postgres Torg slash download site and then from here you just need to download the version that you need so I'm using Windows here and I'm going to be utilizing the download the Installer and I'm gonna select the latest Oshin from my operating system so I'm gonna go for the 64-bit and then down like so the sets up or Postgres is fairly straightforward is a little bit long-winded so let's just head into this insulation a double click and start the installation so press yes and wait okay so now we'll press next and select the installation so from here what we're gonna do is install our own PG admin so we can deselect that and the stack builder we get rid of that so what we're going to install is the Postgres SQL server and the command-line tools so I press next and then next again and then I create a nice little password for my admin so the super user name is going to be called Postgres and in my password is going to be whatever I typed in my password here so that's important when we start to connect to the database so the default user the default super user for Postgres database is called Postgres unlike for example mysql which is normally root so press next and then I select my port number so I'm going to keep it 5 4 3 2 and then use the default there and press next and then next again ok so now that's installed we're now going to go over to Google again and type in PG admin I'm going to download the PG admin tools so from here I'm looking for the download option and then windows again and this is going to be version 4 and I'm for the Exe so obviously we could have just selected this option on the installation of the Postgres server but just like to do this individually just to make sure we got the latest version okay so now that's downloaded let's um start that installation okay so press Next accept and press next and press next and then Next again and then press install okay so once it's finished I would launch it press finish and it would launch the PG admin tool so this is a graphical user interface a management tool that allows us to interface with the Postgres server so from here we can access all of our databases all of our tables and run queries and so forth it just provides a the anyone new to database says it provides a little bit more of a friendly view to the database rather than using the command line so I'm just going to type in a password for that and press ok so in a couple of seconds and type in your admin password that you used earlier there we go so now I'm inside is a survey should have one instance it and that's the Postgres SQL 12 and you can see here this is all databases and there's a database here by default we can just leave that so obviously what we want to do now is we want to build a new database for our django app and we want to then connect our django app to the new database so let's head back into the django application so this is in the the main application in in settings so this is the settings file and you can see that the default option here which I was using for this app was used in the SQL like database so what we can do now is remove the old database because we're going to now connect to the Postgres database so this is the news in configuration so we're going to need to install the adapter to allow us to actually connect to the Postgres database and to provide all the functionality so that we can communicate with the database effectively so let's just install that first so head over to your command prompt and you need to install the Psy cop g2 so have that installed okay so now that's installed we can now head over to the name so this is the name of your database in this case I'll call it test so let's go over to the PG admin again what we're gonna do is just select the databases here right click and create and then select database and here I'm going to make a new database called test obviously you can rename this however you like the owner at this stage is just going to be called Postgres you might want to take this further and add some new users etc but we're just going to use the default options for now so go ahead and save that and you can now see we have a new test database so we're going to use the lies this database to connect to this database and then set up our Django database inside of that so that we can then utilize this database for our Django project so that's the name of the database so the default user is called Postgres the password in my case was called admin so that's the user that's the password that you set originally when you install Postgres for the Postgres user and then the host is going to be localhost so this is just referring to the fact that the installation of Postgres is actually installed on this computer so the localhost and then if you remember the port that we're using is 5 4 3 2 so these are all the settings that you're going to need to connect to your new database ok so next up what we need to do is sync our model to the database so we can do that by running pipe managed rpy migrate and then the run sync database command so I utilized that in the command prompt here and you can see here though says creating tables running deferred SQL and so on now once we've done that we can now migrate our data back into the database so assuming you stored the data dump in the project directory now we're just going to run the load data data dump Jason so in my terminal I type that in and run that and there we go installed 41 objects from one fixture okay so now everything is set head back into PG admin you might need to refresh the page but inside of the test database there is a schema and inside of at there some tables and notice now we have 11 tables if you can see that on your screen and one of them is called core core so that's the name of my database if I go into my model my apt called core and my model is called core you can see that I've got title and so on so if I go back here I can see all those tables inside of core and what I can do now is just run a query so if I right click on core and select query tool what I can do now is select all the data so by running select all from and then the name of my table core core you can see that it returns everything that's inside of my database so let's just check to see if this works now so I'm gonna run my server then this is a simple application which you can have a look at my other videos and see how to build this but this is a simple management content management system so I might add a new item to the database press edit should be saved so I've got a new entry here so that works ok if i refresh this now re-run this query you can see now that my data is indeed inside of the database ok so that was the overview of how to migrate from SQL Lite to a Postgres database with django so as you've seen we've created backup of all the data in a database that's a fairly useful function in general and we've installed the Postgres SQL database and then also the PG admin to allow us to interface with the database so I've gone through a basic set up showing you how to access the database how to migrate and connect your Django app to the Postgres database ok so thanks for watching hopefully you've got this far if you have thank you very much and please check out my other tutorials and support the channel thank you very much
Info
Channel: Very Academy
Views: 17,446
Rating: undefined out of 5
Keywords: django postgresql, install postgresql, django data dump, django tutorial, django for beginners, learn django
Id: ZgRkGfoy2nE
Channel Id: undefined
Length: 11min 59sec (719 seconds)
Published: Thu May 14 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.