django-react-boilerplate
django-react-boilerplate copied to clipboard
"make docker_makemigrations" not working.
Describe the bug
I just created a project, created the .env
and local.py
files, ran when I run the command make docker_makemigrations
it simply don't work. I'm getting a permission denied:
Migrations for 'users':
users/migrations/0001_initial.py
- Create model User
Traceback (most recent call last):
File "/home/user/app/backend/manage.py", line 31, in <module>
execute_from_command_line(sys.argv)
File "/usr/local/lib/python3.11/site-packages/django/core/management/__init__.py", line 442, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python3.11/site-packages/django/core/management/__init__.py", line 436, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/local/lib/python3.11/site-packages/django/core/management/base.py", line 412, in run_from_argv
self.execute(*args, **cmd_options)
File "/usr/local/lib/python3.11/site-packages/django/core/management/base.py", line 458, in execute
output = self.handle(*args, **options)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/django/core/management/base.py", line 106, in wrapper
res = handle_func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/django/core/management/commands/makemigrations.py", line 259, in handle
self.write_migration_files(changes)
File "/usr/local/lib/python3.11/site-packages/django/core/management/commands/makemigrations.py", line 363, in write_migration_files
with open(writer.path, "w", encoding="utf-8") as fh:
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
PermissionError: [Errno 13] Permission denied: '/home/user/app/backend/users/migrations/0001_initial.py'
make: *** [Makefile:43: docker_makemigrations] Erro 1
To Reproduce
- Run
django-admin startproject theprojectname --extension py,yml,json --name Procfile,Dockerfile,docker-compose.yml,README.md,.env.example,.gitignore,Makefile,render.yaml --template=https://github.com/vintasoftware/django-react-boilerplate/archive/boilerplate-release.zip
- Run
cd theprojectname/backend/
- Run
cp theprojectname/settings/local.py.example theprojectname/settings/local.py
- Run
cp .env.example .env
- Uncomment the Postgres line on
.env
- Run
cd ..
- Run
make docker_setup
- Run
make docker_makemigrations
Desktop (please complete the following information):
- OS: Debian 12
I followed the steps but could not reproduce the error: https://asciinema.org/a/nVbubarq02As0JdiO2Ghmya6u
Not sure what could be causing the permission error.
Do you use sudo docker
or just docker
?
Can you confirm your user has permissions over /home/user/app/
?
Hey Vitor, how are you doing? I generally use just docker
. Are you asking about the user inside the container right?
Edit: It seems my user has all necessary permissions in /app/:
But when I try to create a file in /app/backend/users/migrations, I'm getting:
I really don't know why this is happening.
Update: Somehow I fixed this running chmod 777 -R .
. @rangelfinal Do you think is there any security risk in doing so?
It seems that your backend/users/migrations
directory was owned by root - not sure how that would happen, django-admin startproject
should create the files using your current user
A better option than chmod 777
would be changing the owner with chown $USER:$USER -R .
Maybe there's something with my virtual env. I use pyenv to manage my virtual envs. I will recreate the project changing the ownership of the files then. Thank you very much Vitor.
Hello, and thank you for initiating this discussion. @rangelfinal @LuizDMM
I'm encountering a similar issue where Docker containers, by default, create files under the root user (uid=0) on Linux. To address this, I attempted to pass my user ID and group ID to Docker during the image and container build process. Specifically, I set the user ID and group ID in the docker-compose.yaml (user: 1000:1000), and also tried passing UID and GID directly to the docker-compose command.
Despite these efforts, I was unable to run makemigrations successfully without resorting to sudo. This is puzzling and quite time-consuming, and I'm still trying to resolve it. For now, my temporary workaround has been to use sudo for makemigrations or "chmod 777 -R backend/users/migrations", although I'm aware this isn't ideal.
I've spent a significant amount of time on this issue and need to pivot back to coding, but I plan to revisit this problem soon. Any insights or suggestions would be greatly appreciated.
The two more consistent approaches that I found was 1 and 2
PS.: I am using Bookworm too (Debian 12).
Thanks, I will re-open the issue for now.