Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"make docker_makemigrations" not working. #618

Open
LuizDMM opened this issue Sep 21, 2023 · 7 comments
Open

"make docker_makemigrations" not working. #618

LuizDMM opened this issue Sep 21, 2023 · 7 comments
Assignees

Comments

@LuizDMM
Copy link

LuizDMM commented Sep 21, 2023

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

  1. 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
  2. Run cd theprojectname/backend/
  3. Run cp theprojectname/settings/local.py.example theprojectname/settings/local.py
  4. Run cp .env.example .env
  5. Uncomment the Postgres line on .env
  6. Run cd ..
  7. Run make docker_setup
  8. Run make docker_makemigrations

Desktop (please complete the following information):

  • OS: Debian 12
@rangelfinal
Copy link
Contributor

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/?

@LuizDMM
Copy link
Author

LuizDMM commented Sep 21, 2023

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/:

image

But when I try to create a file in /app/backend/users/migrations, I'm getting:
image

I really don't know why this is happening.

@LuizDMM
Copy link
Author

LuizDMM commented Sep 21, 2023

Update: Somehow I fixed this running chmod 777 -R .. @rangelfinal Do you think is there any security risk in doing so?

@rangelfinal
Copy link
Contributor

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 .

@LuizDMM
Copy link
Author

LuizDMM commented Sep 22, 2023

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.

@LuizDMM LuizDMM closed this as completed Sep 22, 2023
@danrleypereira
Copy link

danrleypereira commented Dec 22, 2023

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).

@fjsj
Copy link
Member

fjsj commented Dec 22, 2023

Thanks, I will re-open the issue for now.

@fjsj fjsj reopened this Dec 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants