0

I am working with django.test package in my project, and have implemented some testcases. I have a MySQL database, and have created a test database with no problem.

But now when I am running my tests it shows the below error.

Type 'yes' if you would like to try deleting the test database 'test_sepantadb', or 'no' to cancel: Creating test database for alias 'default'...
Got an error creating the test database: (1007, "Can't create database 'test_sepantadb'; database exists")

And after I type yes to the console, it shows the below errors, and I don't know how to solve them.

Destroying old test database for alias 'default'...
Traceback (most recent call last):
  File "D:\ABDAL\SepantaEnv\lib\site-packages\django\db\backends\utils.py", line 82, in _execute
    return self.cursor.execute(sql)
  File "D:\ABDAL\SepantaEnv\lib\site-packages\django\db\backends\mysql\base.py", line 73, in execute
    return self.cursor.execute(query, args)
  File "D:\ABDAL\SepantaEnv\lib\site-packages\pymysql\cursors.py", line 148, in execute
    result = self._query(query)
  File "D:\ABDAL\SepantaEnv\lib\site-packages\pymysql\cursors.py", line 310, in _query
    conn.query(q)
  File "D:\ABDAL\SepantaEnv\lib\site-packages\pymysql\connections.py", line 548, in query
    self._affected_rows = self._read_query_result(unbuffered=unbuffered)
  File "D:\ABDAL\SepantaEnv\lib\site-packages\pymysql\connections.py", line 775, in _read_query_result
    result.read()
  File "D:\ABDAL\SepantaEnv\lib\site-packages\pymysql\connections.py", line 1156, in read
    first_packet = self.connection._read_packet()
  File "D:\ABDAL\SepantaEnv\lib\site-packages\pymysql\connections.py", line 725, in _read_packet
    packet.raise_for_error()
  File "D:\ABDAL\SepantaEnv\lib\site-packages\pymysql\protocol.py", line 221, in raise_for_error
    err.raise_mysql_exception(self._data)
  File "D:\ABDAL\SepantaEnv\lib\site-packages\pymysql\err.py", line 143, in raise_mysql_exception
    raise errorclass(errno, errval)
pymysql.err.OperationalError: (1050, "Table 'react_arimapredictedvalues' already exists")

I have tried the solution which have been provided in this link. But it does not solve it for me.

I have also run the below command for the second time in my MySQL shell to check the privileges, but again nothing does not change.

mysql> GRANT ALL PRIVILEGES ON test_sepantadb.* TO 'sepanta'@'localhost';
Query OK, 0 rows affected (0.00 sec)

I have also tried two other solutions. I have deleted the test databse from mysql shell with command prompt, and also change my test database name, but none of these two solutions solved my problem.

These are also the content of my django_migrations table in test_sepantadb database: enter image description here

I will be grateful for any help or advice on how to solve this error.

  • check the `migrations` table in your test database and compare with your migration files order. See if there are any different – Linh Nguyen Dec 27 '22 at 11:00
  • Where can I find my test migrations?@LinhNguyen – Aylin Naebzadeh Dec 27 '22 at 11:37
  • in your database, there a should be a database with the name end with _test , check the migrations table for the migration order – Linh Nguyen Dec 29 '22 at 02:19
  • No, actually there is not. I have checked my `django_migrations` table in my local database, but there was no migration related to test database. Also I have executed `makemigrations` and `migrate` commands to sync database changes, but the error still exists...@LinhNguyen – Aylin Naebzadeh Dec 29 '22 at 05:25
  • i don't mean your main database, django will create a new test database https://docs.djangoproject.com/en/4.1/topics/testing/overview/#the-test-database. Please check again – Linh Nguyen Dec 30 '22 at 02:21
  • I know it is too late, but I have updated my post. May you please take a look at it?@LinhNguyen – Aylin Naebzadeh May 04 '23 at 15:53

0 Answers0