Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how cookiecutter django use mysql? #1844

Closed
StupidTAO opened this issue Oct 29, 2018 · 5 comments
Closed

how cookiecutter django use mysql? #1844

StupidTAO opened this issue Oct 29, 2018 · 5 comments

Comments

@StupidTAO
Copy link

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

@browniebroke
Copy link
Member

browniebroke commented Oct 29, 2018

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).

@pydanny
Copy link
Member

pydanny commented Oct 29, 2018

@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

@pydanny pydanny closed this as completed Oct 29, 2018
@xjlin0
Copy link

xjlin0 commented Oct 6, 2019

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 mysql@5.7
echo 'export PATH="/usr/local/opt/mysql@5.7/bin:$PATH"' >> ~/.bash_profile
source ~/.bash_profile
brew services start mysql@5.7
  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!

@doemski
Copy link

doemski commented Apr 28, 2021

For anybody looking to use MySQL / MariaDB with the Docker setup (possibly future me...), here's the changes I needed to get it running:

  1. Add a MariaDB env file under .envs/.local/.mariadb with
MYSQL_ROOT_PASSWORD=test
MYSQL_USER=test
MYSQL_PASSWORD=test
MYSQL_HOST=mariadb
MYSQL_PORT=3306
MYSQL_DATABASE=technical_drawings_database
  1. Change the Docker entrypoint for your app under compose/production/django/entrypoint like this:
    image

  2. Add pymysql to your requirements (requirements/base.txt):

pymysql==1.0.2 (Or newer version)
  1. In your base settings file (config/settings/base.py) add:
import pymysql
pymysql.install_as_MySQLdb()
  1. In your local docker-compose file (local.yml) add the MariaDB container and remove postgres like so:
    image

@mabdullahadeel
Copy link
Contributor

For anybody looking for MySQL option with cookiecutter support,
you can try this fork -> 🦈 https://github.com/mabdullahadeel/cookiecutter-django-mysql

Here are the docs -> 📖 https://cookiecutter-django-mysql.readthedocs.io/en/latest/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants