when i add code at models.py file to make a new column like below,
partnerId = models.IntegerField(null=True, blank=True, default=None) # added
and do "python manage.py makemigrations" and "python manage.py migrate",
and migration is done successfully, but the ‘partnerId’ column’ is created only in local mysql database, not in aws rds mysql database.
how can i deal with this problem?
how i ran ec2 srvr (python manage.py makemigrations)
ubuntu@ip-172-31-0-41:~$ python manage.py makemigrations
Command 'python' not found, did you mean:
command 'python3' from deb python3
command 'python' from deb python-is-python3
ubuntu@ip-172-31-0-41:~$ python3 manage.py makemigrations
python3: can't open file '/home/ubuntu/manage.py': [Errno 2] No such file or directory
ubuntu@ip-172-31-0-41:~$ ls
srv
ubuntu@ip-172-31-0-41:~$ cd srv
ubuntu@ip-172-31-0-41:~/srv$ ls
ubuntu
ubuntu@ip-172-31-0-41:~/srv$ cd ubuntu
ubuntu@ip-172-31-0-41:~/srv/ubuntu$ ls
Dockerfile README.md accounts config docker-compose.prod.yml emotions manage.py schedule
Dockerfile.prod TherapEase-BE api counselees docker-compose.yml main.py requirements.txt
ubuntu@ip-172-31-0-41:~/srv/ubuntu$ python3 manage.py makemigrations
Traceback (most recent call last):
File "/home/ubuntu/srv/ubuntu/manage.py", line 11, in main
from django.core.management import execute_from_command_line
ModuleNotFoundError: No module named 'django'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/home/ubuntu/srv/ubuntu/manage.py", line 22, in <module>
main()
File "/home/ubuntu/srv/ubuntu/manage.py", line 13, in main
raise ImportError(
ImportError: Couldn't import Django. Are you sure it's installed and available on your PYTHONPATH environment variable? Did you forget to activate a virtual environment?
2
Answers
How are you hosting Django application in AWS? EC2 or Elastic Beanstalk? In either case, did you ensure running
python manage.py migrate
in AWS?from your error, it looks like Django isn’t installed on your aws ec2 instance.
You mentioned in the comment that you have to activate
venv
. It works in your local Django terminal because you might have installed Django globally in your system instead of in a virtual environment. So in aws ec2 you first have to createvenv
then activate it and then install your project dependencies includingDjango
then you can run your migrations command and it should work.