Django: attempt to create a read-only database

I just created a Django project with

python manage.py startapp smartrecruitment

Then I synchronized db

 python manage.py syncdb
 Operations to perform:
 Apply all migrations: admin, contenttypes, auth, sessions
 Running migrations:
   Applying contenttypes.0001_initial... OK
   Applying auth.0001_initial... OK
   Applying admin.0001_initial... OK
   Applying sessions.0001_initial... OK

And my superuser added, but I can not access / admin in the browser. I tried to execute the following commands to grant apache permissions, but no luck.

sudo chown apache <folder_containing_db.sqlite3>
sudo chown apache db.sqlite3
+4
source share
4 answers

change the ownership of the project directory and database file www-data

chown www-data:www-data /home/username/Django    
chown www-data:www-data /home/username/Django/db.sqlite  
+8
source

You really have problems with user / group rights: you need to start a web server with a user who has read / write access to your db file (when using sqlite3)

- , - , .

sqlite, .

https://docs.djangoproject.com/en/1.9/ref/settings/#databases

sqlite: sqlite / (, www- , django www-)

some_dir [your_user:your_group]
--- your_django_project [github_user:github_user]
--- another_dir [www-data:www-data]
    |--- db.sqlite3 [www-data:www-data]

- (apache/nginx) www-data​​p >

+3

, CentOS . https://www.digitalocean.com/community/tutorials/how-to-serve-django-applications-with-apache-and-mod_wsgi-on-centos-7

,

sudo usermod -a -G root apache
chmod 710 /root/myproject
chown apache:apache /root/myproject
chown apache:apache /root/myproject/db.sqlite
+1

, , , sqlite, .

:

  • db.sqlite3 ( ) , chown (: chown username db.sqlite3)
  • - ( ) root ( sudo -i gunicorn django runserver)
  • Allow read and write access for all users by running the command chmod 777 db.sqlite3(Dangerous parameter)

Never use the third option if you are not using a web server on your local computer, or if the data in the database is not important to you.

In addition, this error does not occur if you are using a database such as mysql and Postgres. Sqlite is not a good option for a high traffic web server.

-1
source

All Articles