0

I am a university student, and I decided to use Django for my final year project. This means I am limited to using the University's MySQL database server. On the server, I am only allowed to have one database under my name and do not have permission to create any more of my own. I cannot use Django's test database functionality, as I only have one available and cannot create another. So, when I run ./manage.py test, I get the error...

Found 3 test(s).
Creating test database for alias 'default'...
Got an error creating the test database: (1044, "Access denied for user 'comp24394'@'%' to database 'test_comp24394'")

How can I get around this? Is it possible for "test" tables to be created in the main database? Or, can I have the test database on another server from the main - if so, what would be the steps to implement this?

Thank you for any help!

Edit: I have already configured my settings to be connected to my school's database server - The issue is that my user does not have permission to create a new database. I am limited to working with my one database, which is my production database. My question is it possible at all to use the production database to store test data and maybe get it function in a way that the test data is created in a table (say, "test_student"), and then that table is dropped after the test suite is done running? Or, do I have to configure a new setting where I can run my test database? I have to use my school's database server for the production database.

asked Jan 1 at 15:28
7
  • Reading the documentation for just a few minutes after merely googling "django test database": the test runner will otherwise use all of the same database settings you have in your settings file. So, see docs.djangoproject.com/en/5.1/topics/testing/overview/… and also see docs.djangoproject.com/en/5.1/topics/settings/#django-settings Commented Jan 1 at 16:48
  • Hi @topsail . Despite this documentation, I am still confused - because right after that sentence, it says " The test database is created by the user specified by USER, so you’ll need to make sure that the given user account has sufficient privileges to create a new database on the system". The problem is I don't have these privileges - I cannot create a new database on the system - I can only make tables on my one "production" database. So, I don't think this answers my question - which is if I can get around not using a test database, as I don't have the privilege to create a new database. Commented Jan 1 at 18:56
  • The USER is also set in the settings. It is the user of the server/database you connect to. Your test user can have the same username if you want, but essentially these are users in different databases regardless.... Commented Jan 1 at 19:26
  • ... This is just all very normal database connection string stuff - you provide the connection information including these things. For example, the most basic MySql connection string: Server=myServerAddress;Database=myDataBase;Uid=myUsername;Pwd=myPassword; where Uid is the USER in this case. Django settings will at the end of the day become used for these connection string settings. Commented Jan 1 at 19:28
  • 1
    Why do you want to run the tests against your universities database server anyway? Just spin up a MySQL server on your own machine or is it that you don't have permissions for that as well? Surely you're not doing all your development work on what you call your production database? Commented Jan 2 at 11:55

1 Answer 1

0

It is not a good practice to run your tests on a production database because it might lead to data corruption, impact on the performance of the server and have other unintended consequences.

Django Tests that require a database creates separate, blank databases for the tests and are not intended to be run on the production database.

Your best option, as has been suggested in the comments is to spin up a MySQL server on your local machine.

answered Jun 7 at 11:11
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.