Cookiecutter-django: how cookiecutter django use mysql?

Created on 29 Oct 2018  路  3Comments  路  Source: pydanny/cookiecutter-django

I need use mysql database in the project of cookiecutter-django,but cookiecutter only support postgresql,what should i do?

Most helpful comment

Here are my steps to use MySQL 5.7 on OS 10.13.6. My local mysql administrator account is root without password, so I can enter local mysql console by mysql -uroot and create the database:

  1. follow cookiecutter-django instructions to start a project
    https://github.com/pydanny/cookiecutter-django#usage
    https://cookiecutter-django.readthedocs.io/en/latest/developing-locally.html

  2. install MySQL 5.7, ensure mysql is in the path, start the MySQL service

brew install [email protected]
echo 'export PATH="/usr/local/opt/[email protected]/bin:$PATH"' >> ~/.bash_profile
source ~/.bash_profile
brew services start [email protected]
  1. install mysqlclient for python, please ensure you are still in the virtual env for the python version you need.
python -V
pip install mysqlclient django-environ
  1. change database setting of Django setup by cookiecutter, in (your project)/(your app)/config/settings/base.py, around DATABASES dictionary
    # "default": env.db("DATABASE_URL", default="postgres:///<your database name>")
    "default": env.db("DATABASE_URL", default="mysql://root:@127.0.0.1:3306/<your database name>")

And it just works! Enjoy!

All 3 comments

You're right, cookiecutter-django only supports postgres.

However, at the end of day, the output is a Django project, so I suggest to refer to the documentation from Django itself, especially the DATABASES setting. You will need to swap out the settings we generate by the appropriate one for mysql.

If you use Docker, you will need to change the postgres service to use a MySQL Docker image.

I've never done it, but it should be feasible. Feel free to add more information here for others, but I do not think we plan to support MySQL in the cookiecutter-django (see #111).

@browniebroke is correct, Cookiecutter Django will not be supporting MySQL. That could change per my specification in #111.

Rather than changing out postgre for mysql, having you considered staying with postgre? Here are some considerations:

  • PostgreSQL is the default database for Django. There are features in Django that only work for PostgreSQL
  • PostgreSQL is much better at handling database migrations than MySQL. It's really nice when for large tables things don't get locked for hours

Here are my steps to use MySQL 5.7 on OS 10.13.6. My local mysql administrator account is root without password, so I can enter local mysql console by mysql -uroot and create the database:

  1. follow cookiecutter-django instructions to start a project
    https://github.com/pydanny/cookiecutter-django#usage
    https://cookiecutter-django.readthedocs.io/en/latest/developing-locally.html

  2. install MySQL 5.7, ensure mysql is in the path, start the MySQL service

brew install [email protected]
echo 'export PATH="/usr/local/opt/[email protected]/bin:$PATH"' >> ~/.bash_profile
source ~/.bash_profile
brew services start [email protected]
  1. install mysqlclient for python, please ensure you are still in the virtual env for the python version you need.
python -V
pip install mysqlclient django-environ
  1. change database setting of Django setup by cookiecutter, in (your project)/(your app)/config/settings/base.py, around DATABASES dictionary
    # "default": env.db("DATABASE_URL", default="postgres:///<your database name>")
    "default": env.db("DATABASE_URL", default="mysql://root:@127.0.0.1:3306/<your database name>")

And it just works! Enjoy!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

webyneter picture webyneter  路  4Comments

saschalalala picture saschalalala  路  4Comments

webyneter picture webyneter  路  3Comments

webyneter picture webyneter  路  4Comments

huydbui picture huydbui  路  3Comments