Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

call_command makemigrations does not work on Elastic Beanstalk

I have a scenario, where I need to create a table dynamically, To create the table dynamically I have written code to create a model.py file with the table content that I want to create.

Once this file get created then I want to perform the makemigrations command from the code itself like

 from django.core.management import call_command
 call_command('makemigrations')
 call_command('migrate')

it is working fine in my local as well in AWS EC2 instance, but it is not working into the Elastic Beanstalk (eb). and when I'm trying to run the makemigrations command manually from the eb ssh then it gives me the following error.

PermissionError: [Errno 13] Permission denied: '/opt/python/bundle/47/app/quotations/migrations/0036_dynamic_table.py'

Anyone have any idea how can I handle this situation.

One Other thing is that as I'm creating new dynamic models So how can I push that code to the git, as on new deployment EBS will replace the existing code to new code, so in this way I will lose the files that I created in EBS using these commands

Thanks

like image 978
Mahendra Garg Avatar asked Feb 19 '18 08:02

Mahendra Garg


2 Answers

I agree with Eddie that you need to modify the permissions of the migrations folder.

The migrations folder is located at: /opt/python/current/app/quotations/migrations/

You probably need to do something like:

subprocess.call(['chmod', '-R', '+w', '/opt/python/current/app/quotations/migrations/'])

You'll probably need this before and/or after the makemigrations call.

Please comment if you have further issues.

like image 164
Pranay Majmundar Avatar answered Nov 17 '22 11:11

Pranay Majmundar


This looks like a simple permissions error and may not have to do with EBS itself. Do an ls -al /opt/python/bundle/47/app/quotations/migrations/ and look to see if 0036_dynamic_table.py already exists. If so, delete it, if not, look at the permissions along that path to verify that the user that the migration runs-as has permissions to write and execute all the directories.

Now that I think of it, its most likely that you are not running the migration commands as the same user that owns the directory structure. Take a look.

like image 1
Cargo23 Avatar answered Nov 17 '22 12:11

Cargo23