Using MySQL as Database and Connecting it with Django #10
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Related Issue: #8
This PR will resolve #8 issue.
Major change
I modified 'backend/backend_python/settings.py' to use MySQL as our default databases.
How to use MySQL with Django in your local environment
Even though it was a really small change, I think each of us should setup environment for this. Because we can't use a server like Azure all the time(at least at the early sprints), I think each of us should install MySQL in environment, create a database with the specific name, and also create an user with the specific name and password. Please let me know if you have a better idea.
Please follow the instruction below. I suppose you use Linux like Ubuntu or MacOS.
1. Install MySQL in your environment.
Download it from https://dev.mysql.com/downloads/mysql/ or in any other way. (I'm using the version 'MySQL Community Server 8.0.17'.)
When installing, it would give you a temporary password or let you set your own password for root. Whatever the password is, it's ok. We'll create another user(not root) for PapersFeed.
2. Log in to mysql as root, and create a database and an user.
In terminal, please type this and enter the password.
mysql -u root -p
By type this, create a DB with the name 'PapersFeed_DB'.
mysql> CREATE DATABASE PapersFeed_DB;
And please create user with this command.
mysql> CREATE USER 'PapersFeed'@'localhost' IDENTIFIED WITH mysql_native_password BY 'swpp2019team3';
You should give the user all privileges of 'PapersFeed_DB'.
mysql> GRANT ALL PRIVILEGES ON PapersFeed_DB.* to 'PapersFeed'@'localhost';
3. Set 'mysql_native_password' as 'default-authentication-plugin'.
This process is related with the issue 'https://stackoverflow.com/questions/50469587/django-db-utils-operationalerror-2059-authentication-plugin-caching-sha2-pas'.
Please type 'exit' to exit from mysql.
On terminal, please type this to check your setting.
mysqld --verbose --help
Maybe you can find 'default-authentication-plugin' is 'caching_sha2_password'.
You can change this by modifying or creating the file '~/.my.cnf'.(You can find some other choices by typing
mysql --help | grep my.cnf
.)In the file, please make it include below two lines.
4. Install mysqlclient.
For Django to deal with MySQL, mysqlclient is needed.
I specified it with the version in 'requirements.txt'. Please install it in some ways like
pip3 install -r /path/to/requirements.txt
.5. (Optional) Set DYLD_LIBRARY_PATH in your env.
In my case, even though I installed mysqlclient, when I ran 'manage.py', it couldn't find the module. Then you should set DYLD_LIBRARY_PATH in your shell setting file like '~/.bashrc', '~/.zshrc', etc.
Please make it include this.
export DYLD_LIBRARY_PATH="/usr/local/mysql/lib/:$DYLD_LIBRARY_PATH"
6. Migrate!
In the 'backend' dir, please type this to make migrations and migrate.
Please let me know immediately when you encounter some problems related with this.
Minor change
I added a '.gitignore' file in the 'backend' dir.
And I delete 'lazy-object-proxy' from 'requirements.txt' because it is specified with the version '0.0.0', which is strange.(@abcthing)
Also, I find ApiError defined in 'utils.py' of the 'application' dir is always called when I run 'manage.py'.(@abcthing) To avoid confusion, I modified the error message to 'API ERROR(fixme)'.