0

It's not a duplicate, I've already seen other posts with the same title, but the problem doesn't occur in the same moment as in these posts and answers doesn't work.

After basic setup on new Ubuntu 20.04 LTS Machine i cloned my repository, created virtual environment, installed dependencies, installed mysql, edited my.cnf file with database informations and everything was working fine to the moment i did python3 manage.py migrate. I have error (1146, "Table 'todochat_data.app_server' doesn't exist"). Well it obviously doesn't exist because my database is empty, but I don't know how to fix it. I've already done these basic project setups dozens of times, but I've never seen this problem.

todochat_data.app_server model

[client]
database = todochat_data
user = todochat_user
password = database_user_password
default-character-set = utf8

What I tried:

  • python manage.py migrate --database dataset
  • python manage.py migrate --fake
  • commenting out app in installed_apps
  • python manage.py migrate --fake app zero
  • migrate --fake-initial

History of commands:

  • 9 git clone https://github.com/n3rsti/ToDoChat.git
  • 10 cd ToDoChat/
  • 11 virtualenv -p python3 venv/
  • 12 source venv/bin/activate
  • 13 ls
  • 14 pip3 install -r requirements.txt
  • 15 nano todochat/todochat/settings.py
  • 16 sudo mysql -u root
  • 17 sudo apt install mysql-server
  • 18 sudo mysql -u root # I created todochat_user here using this template CREATE USER 'djangouser'@'%' IDENTIFIED WITH mysql_native_password BY 'password';
  • 19 sudo nano /etc/mysql/my.cnf
  • 20 sudo systemctl daemon-reload
  • 21 sudo systemctl restart mysql
  • 22 cd todochat/
  • 23 python manage.py migrate
double-beep
  • 5,031
  • 17
  • 33
  • 41
  • Try `python manage.py migrate --fake zero`. Also are you sure you are using the correct database? Check your database settings in `settings.py` – Abdul Aziz Barkat Mar 04 '21 at 15:59
  • I'm sure im using correct db and unfortunately your command gives me the same error. – Krzysiek Witucki Mar 04 '21 at 16:04
  • Looking at the repository you have linked there are a lot of migrations With minor changes. Looking in the migrations of the app `app` the model `Server` has been deleted and recreated. Perhaps there may be some conflicts in your migrations. If it is possible delete all migrations and run `python manage.py makemigrations` and then migrate. – Abdul Aziz Barkat Mar 04 '21 at 16:15
  • I can't makemigrations either. But it might be the case with recreating Server model because I've had some problems with models and I had to delete and remake migrations. – Krzysiek Witucki Mar 04 '21 at 16:19
  • I found a solution, It might not be the best in all cases but it's working for me. Basically i did `git checkout` to one of the previous commits and I made migrations there. Then i came back to master and it's working perfectly fine. I think it can be solved through remaking migrations (deleting and making new with makemigrations) as well. – Krzysiek Witucki Mar 04 '21 at 16:25
  • Thanks for help @AbdulAzizBarkat ! – Krzysiek Witucki Mar 04 '21 at 16:26
  • Hey, I took a look at your repo, and think it might be because of your signal handlers, which import the Profile model. These run before any migrations, and when the db is empty (e.g. when cloning the repo), it breaks before it gets a chance to run any migrations. I've written up an answer [here](https://stackoverflow.com/q/73786126/) – platelminto Sep 20 '22 at 12:06

0 Answers0