官术网_书友最值得收藏!

Installing PostgreSQL

You are currently using SQLite for your blog project. This is sufficient for development purposes. However, for a production environment, you will need a more powerful database, such as PostgreSQL, MySQL, or Oracle. We will change our database to PostgreSQL to benefit from its full-text search features.

If you are using Linux, install dependencies for PostgreSQL to work with Python, like this:

sudo apt-get install libpq-dev python-dev

Then, install PostgreSQL with the following command:

sudo apt-get install postgresql postgresql-contrib

If you are using macOS X or Windows, download PostgreSQL from https://www.postgresql.org/download/ and install it.

You also need to install the Psycopg2 PostgreSQL adapter for Python. Run the following command in the shell to install it:

pip install psycopg2==2.7.4

Let's create a user for our PostgreSQL database. Open the shell and run the following commands:

su postgres
createuser -dP blog

You will be prompted a password for the new user. Enter the desired password and then create the blog database and give the ownership to the blog user you just created with the following command:

createdb -E utf8 -U blog blog

Then, edit the settings.py file of your project and modify the DATABASES setting to make it look as follows:

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'blog',
'USER': 'blog',
'PASSWORD': '*****',
}
}

Replace the preceding data with the database name and credentials for the user you created. The new database is empty. Run the following command to apply all database migrations:

python manage.py migrate

Finally, create a superuser with the following command:

python manage.py createsuperuser

You can now run the development server and access the administration site at http://127.0.0.1:8000/admin/ with the new superuser.

Since we switched the database, there are no posts stored in it. Populate your new database with a couple of sample blog posts so that you can perform searches against the database.

主站蜘蛛池模板: 社会| 冷水江市| 宝山区| 西和县| 商都县| 锡林郭勒盟| 龙江县| 黄骅市| 昭觉县| 肇源县| 札达县| 辽宁省| 瑞丽市| 无为县| 格尔木市| 惠水县| 郴州市| 阿拉善左旗| 葵青区| 平阳县| 邛崃市| 喀喇沁旗| 左云县| 舞阳县| 聂拉木县| 沧源| 巩留县| 庄河市| 金门县| 中牟县| 驻马店市| 沂南县| 个旧市| 贵德县| 尚志市| 六安市| 南城县| 获嘉县| 邵阳县| 上林县| 铅山县|