migrations are not taking place after pushing my code on heroku...? - python

Well its been 12 hours and i'm still unable to deploy my project properly. I just dont know what is wrong happening. You guys can see throughing error that such models not exist . But i'm trying to make migrations my heroku run python manage.py makemigrations and it throughing me this traceback. My code is working perfectly fine in local but on the server side this is happening. Please help me out.
Traceback (most recent call last):
File "manage.py", line 22, in <module>
main()
File "manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/__init__.py", line 401, in execute_from_command_line
utility.execute()
File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/__init__.py", line 395, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/base.py", line 330, in run_from_argv
self.execute(*args, **cmd_options)
File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/base.py", line 368, in execute
self.check()
File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/base.py", line 396, in check
databases=databases,
File "/app/.heroku/python/lib/python3.6/site-packages/django/core/checks/registry.py", line 70, in run_checks
new_errors = check(app_configs=app_configs, databases=databases)
File "/app/.heroku/python/lib/python3.6/site-packages/django/core/checks/urls.py", line 13, in check_url_config
return check_resolver(resolver)
File "/app/.heroku/python/lib/python3.6/site-packages/django/core/checks/urls.py", line 23, in check_resolver
return check_method()
File "/app/.heroku/python/lib/python3.6/site-packages/django/urls/resolvers.py", line 408, in check
for pattern in self.url_patterns:
File "/app/.heroku/python/lib/python3.6/site-packages/django/utils/functional.py", line 48, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/app/.heroku/python/lib/python3.6/site-packages/django/urls/resolvers.py", line 589, in url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "/app/.heroku/python/lib/python3.6/site-packages/django/utils/functional.py", line 48, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/app/.heroku/python/lib/python3.6/site-packages/django/urls/resolvers.py", line 582, in urlconf_module
return import_module(self.urlconf_name)
File "/app/.heroku/python/lib/python3.6/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 678, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/app/dotescrow/urls.py", line 27, in <module>
path('accounts/', include('accounts.urls',namespace = 'accounts')),
File "/app/.heroku/python/lib/python3.6/site-packages/django/urls/conf.py", line 34, in include
urlconf_module = import_module(urlconf_module)
File "/app/.heroku/python/lib/python3.6/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 678, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
from accounts import views
File "/app/accounts/views.py", line 5, in <module>
from accounts.forms import UserCreateForm,CoustomLoginForm
File "/app/accounts/forms.py", line 54, in <module>
class UserCreateForm(UserCreationForm):
File "/app/.heroku/python/lib/python3.6/site-packages/django/forms/models.py", line 268, in __new__
raise FieldError(message)
django.core.exceptions.FieldError: Unknown field(s) (gender, nationality, age) specified for User
PS C:\Users\AHMED\Dotesrow\dotescrow> heroku run python manage.py makemigrations
Running python manage.py makemigrations on ⬢ dotescrow... up, run.6085 (Free)
Traceback (most recent call last):
File "manage.py", line 22, in <module>
main()
File "manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/__init__.py", line 401, in execute_from_command_line
utility.execute()
File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/__init__.py", line 395, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/base.py", line 330, in run_from_argv
self.execute(*args, **cmd_options)
File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/base.py", line 368, in execute
self.check()
File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/base.py", line 396, in check
databases=databases,
File "/app/.heroku/python/lib/python3.6/site-packages/django/core/checks/registry.py", line 70, in run_checks
new_errors = check(app_configs=app_configs, databases=databases)
File "/app/.heroku/python/lib/python3.6/site-packages/django/core/checks/urls.py", line 13, in check_url_config
return check_resolver(resolver)
File "/app/.heroku/python/lib/python3.6/site-packages/django/core/checks/urls.py", line 23, in check_resolver
return check_method()
File "/app/.heroku/python/lib/python3.6/site-packages/django/urls/resolvers.py", line 408, in check
for pattern in self.url_patterns:
File "/app/.heroku/python/lib/python3.6/site-packages/django/utils/functional.py", line 48, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/app/.heroku/python/lib/python3.6/site-packages/django/urls/resolvers.py", line 589, in url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "/app/.heroku/python/lib/python3.6/site-packages/django/utils/functional.py", line 48, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/app/.heroku/python/lib/python3.6/site-packages/django/urls/resolvers.py", line 582, in urlconf_module
return import_module(self.urlconf_name)
File "/app/.heroku/python/lib/python3.6/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 678, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/app/dotescrow/urls.py", line 27, in <module>
path('accounts/', include('accounts.urls',namespace = 'accounts')),
File "/app/.heroku/python/lib/python3.6/site-packages/django/urls/conf.py", line 34, in include
urlconf_module = import_module(urlconf_module)
File "/app/.heroku/python/lib/python3.6/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 678, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/app/accounts/urls.py", line 4, in <module>
from accounts import views
File "/app/accounts/views.py", line 5, in <module>
from accounts.forms import UserCreateForm,CoustomLoginForm
File "/app/accounts/forms.py", line 54, in <module>
class UserCreateForm(UserCreationForm):
File "/app/.heroku/python/lib/python3.6/site-packages/django/forms/models.py", line 268, in __new__
raise FieldError(message)
django.core.exceptions.FieldError: Unknown field(s) (age, nationality, gender) specified for User
Usercreateform
class UserCreateForm(UserCreationForm):
class Meta:
fields = ["first_name","last_name","username","email","password1","password2","age","gender","nationality"]
model = User
Gender = (
('one','Male'),
('two','Female'),
)
widgets ={
'username' : forms.TextInput(attrs={'class':'form-control'}),
'email' : forms.TextInput(attrs={'class':'form-control'}),
'age' : forms.TextInput(attrs={'class':'form-control'}),
'gender' : forms.Select(choices=Gender,attrs={'class': 'form-control'}),
'nationality' : forms.TextInput(attrs={'class':'form-control'}),
'password1' : forms.TextInput(attrs={'class':'form-control'}),
'password2' : forms.TextInput(attrs={'class':'form-control'}),
}
def clean_email(self):
email = self.cleaned_data["email"]
if User.objects.filter(email__iexact=email).exists():
raise forms.ValidationError("Email is invalid")
return email
def clean_age(self):
age = self.cleaned_data["age"]
print(age,'hm here')
if age < 18:
print(age,'hm here')
raise forms.ValidationError("You age should be 18 plus")
return age
def __init__(self,*args, **kwargs):
super().__init__(*args, **kwargs)
self.fields['first_name'].widget.attrs['placeholder'] = ('First name')
self.fields['first_name'].label = ''
self.fields['last_name'].widget.attrs['placeholder'] = ('Last name')
self.fields['last_name'].label = ''
self.fields['username'].widget.attrs['placeholder'] = ('Username')
self.fields['username'].label = ''
self.fields['email'].widget.attrs['placeholder'] = ('Email')
self.fields['email'].label = ''
self.fields['age'].widget.attrs['placeholder'] = ('Age')
self.fields['age'].label = ''
self.fields['gender'].widget.attrs['placeholder'] = ('Gender')
self.fields['gender'].label = ''
self.fields['nationality'].widget.attrs['placeholder'] = ('Nationality')
self.fields['nationality'].label = ''
self.fields['password1'].widget.attrs['placeholder'] = ('Password')
self.fields['password1'].label = ''
self.fields['password2'].widget.attrs['placeholder'] = ('Confirm Password')
self.fields['password2'].label = ''
for fieldname in ['username', 'password1', 'password2']:
self.fields[fieldname].help_text = None
if more code is require then tell me in a comment session. i will update my question with that information.

You should not run makemigrations on heroku. Migrations is something that should be added to your repo and then your deployment plan uses those migration files to execute migrations on the DB.
Heroku has a release phase when python manage.py migrate should be executed. If migrations fail, new code that uses them won't be deployed.
If you don't want to add this phase because you don't feel like it - no problem. Just don't run makemigrations.
If, for some reason, you won't be able to create migrations locally, comment out this form, run makemigrations, run migrate and uncomment this code.
If heroku still complains, repeat these steps ^ on heroku as well.
But the idea is that on heroku you run only
python manage.py migrate (release phase if possible)
gunicorn something something (web dyno)

Related

I am not able to make migrations to the following file?

I am trying to create the migration of the following models.py code but the following error is occuring ???(I am learning Web-Devlopment from CS50-Web Devlopment Courese)
Can Anyone help me solve the error is I have very little knowledge about django, sqlite and as well as Web-devlopment.
from django.db import models
class Flight(models.Model):
origin = models.CharField(max_length=64)
destination = models.CharField(max_length=64)
duration = models.IntegerField()
The error is as follows:
Traceback (most recent call last):
File "C:\Users\Dell\Desktop\Books\Programming\Web Devlopment\Lecture-4\airline\manage.py", line 22, in <module>
main()
File "C:\Users\Dell\Desktop\Books\Programming\Web Devlopment\Lecture-4\airline\manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "C:\Users\Dell\AppData\Local\Programs\Python\Python310\lib\site-packages\django\core\management\__init__.py", line 446, in execute_from_command_line
utility.execute()
File "C:\Users\Dell\AppData\Local\Programs\Python\Python310\lib\site-packages\django\core\management\__init__.py", line 440, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Users\Dell\AppData\Local\Programs\Python\Python310\lib\site-packages\django\core\management\base.py", line 414, in run_from_argv
self.execute(*args, **cmd_options)
File "C:\Users\Dell\AppData\Local\Programs\Python\Python310\lib\site-packages\django\core\management\base.py", line 455, in execute
self.check()
File "C:\Users\Dell\AppData\Local\Programs\Python\Python310\lib\site-packages\django\core\management\base.py", line 487, in check
all_issues = checks.run_checks(
File "C:\Users\Dell\AppData\Local\Programs\Python\Python310\lib\site-packages\django\core\checks\registry.py", line 88, in run_checks
new_errors = check(app_configs=app_configs, databases=databases)
File "C:\Users\Dell\AppData\Local\Programs\Python\Python310\lib\site-packages\django\core\checks\urls.py", line 14, in check_url_config
return check_resolver(resolver)
File "C:\Users\Dell\AppData\Local\Programs\Python\Python310\lib\site-packages\django\core\checks\urls.py", line 24, in check_resolver
return check_method()
File "C:\Users\Dell\AppData\Local\Programs\Python\Python310\lib\site-packages\django\urls\resolvers.py", line 480, in check
for pattern in self.url_patterns:
File "C:\Users\Dell\AppData\Local\Programs\Python\Python310\lib\site-packages\django\utils\functional.py", line 49, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "C:\Users\Dell\AppData\Local\Programs\Python\Python310\lib\site-packages\django\urls\resolvers.py", line 696, in url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "C:\Users\Dell\AppData\Local\Programs\Python\Python310\lib\site-packages\django\utils\functional.py", line 49, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "C:\Users\Dell\AppData\Local\Programs\Python\Python310\lib\site-packages\django\urls\resolvers.py", line 689, in urlconf_module
return import_module(self.urlconf_name)
File "C:\Users\Dell\AppData\Local\Programs\Python\Python310\lib\importlib\__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 883, in exec_module
File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
File "C:\Users\Dell\Desktop\Books\Programming\Web Devlopment\Lecture-4\airline\airline\urls.py", line 22, in <module>
path('flights/', include('flights.urls') ),
File "C:\Users\Dell\AppData\Local\Programs\Python\Python310\lib\xml\etree\ElementInclude.py", line 128, in include
_include(elem, loader, base_url, max_depth, set())
File "C:\Users\Dell\AppData\Local\Programs\Python\Python310\lib\xml\etree\ElementInclude.py", line 136, in _include
if e.tag == XINCLUDE_INCLUDE:
AttributeError: 'str' object has no attribute 'tag'
You are importing include from wrong module.Probably from xml.etree.ElementInclude
So change
from xml.etree.ElementInclude import include
to
from django.urls import include
in your airline/urls.py file.

EOF while scanning triple-quoted string literal while creating a TextField value for a django model. (how to correctly concat strings)

this is the model i am creating:
class Notification(models.Model):
user = models.ForeignKey("User", on_delete=models.CASCADE, related_name="notifications")
text = models.TextField()
timestamp = models.DateTimeField(auto_now_add=True)
The "text" field is giving me issues. This is how i am trying to create an instance:
Notification.objects.create(user=instance.post.owner, text=instance.user.username + ' liked your post')
"instance.user.username" is a CharField. What is the correct way of adding that to a string?
this is the complete traceback i am getting:
Traceback (most recent call last):
File "manage.py", line 22, in <module>
main()
File "manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "/home/abhigya/.local/lib/python3.8/site-packages/django/core/management/__init__.py", line 401, in execute_from_command_line
utility.execute()
File "/home/abhigya/.local/lib/python3.8/site-packages/django/core/management/__init__.py", line 395, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/abhigya/.local/lib/python3.8/site-packages/django/core/management/base.py", line 330, in run_from_argv
self.execute(*args, **cmd_options)
File "/home/abhigya/.local/lib/python3.8/site-packages/django/core/management/base.py", line 368, in execute
self.check()
File "/home/abhigya/.local/lib/python3.8/site-packages/django/core/management/base.py", line 392, in check
all_issues = checks.run_checks(
File "/home/abhigya/.local/lib/python3.8/site-packages/django/core/checks/registry.py", line 70, in run_checks
new_errors = check(app_configs=app_configs, databases=databases)
File "/home/abhigya/.local/lib/python3.8/site-packages/django/core/checks/urls.py", line 40, in check_url_namespaces_unique
all_namespaces = _load_all_namespaces(resolver)
File "/home/abhigya/.local/lib/python3.8/site-packages/django/core/checks/urls.py", line 57, in _load_all_namespaces
url_patterns = getattr(resolver, 'url_patterns', [])
File "/home/abhigya/.local/lib/python3.8/site-packages/django/utils/functional.py", line 48, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/home/abhigya/.local/lib/python3.8/site-packages/django/urls/resolvers.py", line 589, in url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "/home/abhigya/.local/lib/python3.8/site-packages/django/utils/functional.py", line 48, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/home/abhigya/.local/lib/python3.8/site-packages/django/urls/resolvers.py", line 582, in urlconf_module
return import_module(self.urlconf_name)
File "/usr/lib/python3.8/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 783, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/home/abhigya/Documents/WEB-DEV/iiitu/iiitu/urls.py", line 22, in <module>
path('', include("events.urls")),
File "/home/abhigya/.local/lib/python3.8/site-packages/django/urls/conf.py", line 34, in include
urlconf_module = import_module(urlconf_module)
File "/usr/lib/python3.8/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 783, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/home/abhigya/Documents/WEB-DEV/iiitu/events/urls.py", line 2, in <module>
from . import views
File "/home/abhigya/Documents/WEB-DEV/iiitu/events/views.py", line 583
Notification.objects.create(user=instance.post.owner, text=instance.user.username + ' liked your post')
^
SyntaxError: EOF while scanning triple-quoted string literal
Change
text = models.TextField()
To
text = models.CharField(max_length=20)
You not define the length of the field

Error in importing a module in rest_framework, while creating rest API using Django framework

I created a web application using Djanjo framework, and then when I am trying to create a REST API, after configuring all the relevant files such as models.py, admin.py, serializers.py, views.py, and settings.py. It shows an error while importinng the model from rest_framework. The traceback is as follows:
*Traceback (most recent call last):
File "C:\Users\dmandal\AppData\Local\Continuum\anaconda3\lib\threading.py", line 917, in _bootstrap_inner
self.run()
File "C:\Users\dmandal\AppData\Local\Continuum\anaconda3\lib\threading.py", line 865, in run
self._target(*self._args, **self._kwargs)
File "C:\Users\dmandal\AppData\Local\Continuum\anaconda3\lib\site-packages\django\utils\autoreload.py", line 54, in wrapper
fn(*args, **kwargs)
File "C:\Users\dmandal\AppData\Local\Continuum\anaconda3\lib\site-packages\django\core\management\commands\runserver.py", line 117, in inner_run
self.check(display_num_errors=True)
File "C:\Users\dmandal\AppData\Local\Continuum\anaconda3\lib\site-packages\django\core\management\base.py", line 390, in check
include_deployment_checks=include_deployment_checks,
File "C:\Users\dmandal\AppData\Local\Continuum\anaconda3\lib\site-packages\django\core\management\base.py", line 377, in _run_checks
return checks.run_checks(**kwargs)
File "C:\Users\dmandal\AppData\Local\Continuum\anaconda3\lib\site-packages\django\core\checks\registry.py", line 72, in run_checks
new_errors = check(app_configs=app_configs)
File "C:\Users\dmandal\AppData\Local\Continuum\anaconda3\lib\site-packages\django\core\checks\urls.py", line 13, in check_url_config
return check_resolver(resolver)
File "C:\Users\dmandal\AppData\Local\Continuum\anaconda3\lib\site-packages\django\core\checks\urls.py", line 23, in check_resolver
return check_method()
File "C:\Users\dmandal\AppData\Local\Continuum\anaconda3\lib\site-packages\django\urls\resolvers.py", line 399, in check
for pattern in self.url_patterns:
File "C:\Users\dmandal\AppData\Local\Continuum\anaconda3\lib\site-packages\django\utils\functional.py", line 80, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "C:\Users\dmandal\AppData\Local\Continuum\anaconda3\lib\site-packages\django\urls\resolvers.py", line 584, in url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "C:\Users\dmandal\AppData\Local\Continuum\anaconda3\lib\site-packages\django\utils\functional.py", line 80, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "C:\Users\dmandal\AppData\Local\Continuum\anaconda3\lib\site-packages\django\urls\resolvers.py", line 577, in urlconf_module
return import_module(self.urlconf_name)
File "C:\Users\dmandal\AppData\Local\Continuum\anaconda3\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 728, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "C:\myproject1\myproject1\urls.py", line 19, in <module>
from webapp import views
File "C:\myproject1\webapp\views.py", line 9, in <module>
from . serializers import employeesSerializer
File "C:\myproject1\webapp\serializers.py", line 2, in <module>
from rest_framework import employees
ImportError: cannot import name 'employees' from 'rest_framework' (C:\Users\dmandal\AppData\Local\Continuum\anaconda3\lib\site-packages\rest_framework\__init__.py)*
The serializer.py is as follows:
from rest_framework import serializers
from rest_framework import employees
class employeesSerializer(serializers.ModelSerializer):
class Meta:
model = employees
# fields = ('firstname','lastname')
fields = '__all__'
It's name conflict. Please change the name of your app to something else other then rest_framework.

ModuleNotFoundError: No module named 'api.serlializer'

I've installed Django 3.1.4 and djangorestframework 3.12.2.
I am attempting to run makemigrations for a music website I am building and I keep getting this error in the terminal and haven't been able to figure out what is causing it.
(Django_React) PS C:\Users\BB_SO\desktop\dev\Django_React\music_site> python .\manage.py makemigrations Traceback (most recent call last):
File ".\manage.py", line 22, in <module>
main()
File ".\manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "C:\Users\BB_SO\desktop\dev\Django_React\lib\site-packages\django\core\management\__init__.py", line 401, in execute_from_command_line
utility.execute()
File "C:\Users\BB_SO\desktop\dev\Django_React\lib\site-packages\django\core\management\__init__.py", line 395, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Users\BB_SO\desktop\dev\Django_React\lib\site-packages\django\core\management\base.py", line 330, in run_from_argv
self.execute(*args, **cmd_options)
File "C:\Users\BB_SO\desktop\dev\Django_React\lib\site-packages\django\core\management\base.py", line 368, in execute
self.check()
File "C:\Users\BB_SO\desktop\dev\Django_React\lib\site-packages\django\core\management\base.py", line 396, in check
databases=databases,
File "C:\Users\BB_SO\desktop\dev\Django_React\lib\site-packages\django\core\checks\registry.py", line 70, in run_checks
new_errors = check(app_configs=app_configs, databases=databases)
File "C:\Users\BB_SO\desktop\dev\Django_React\lib\site-packages\django\core\checks\urls.py", line 13, in check_url_config
return check_resolver(resolver)
File "C:\Users\BB_SO\desktop\dev\Django_React\lib\site-packages\django\core\checks\urls.py", line 23, in check_resolver
return check_method()
File "C:\Users\BB_SO\desktop\dev\Django_React\lib\site-packages\django\urls\resolvers.py", line 408, in check
for pattern in self.url_patterns:
File "C:\Users\BB_SO\desktop\dev\Django_React\lib\site-packages\django\utils\functional.py", line 48, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "C:\Users\BB_SO\desktop\dev\Django_React\lib\site-packages\django\urls\resolvers.py", line 589, in url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "C:\Users\BB_SO\desktop\dev\Django_React\lib\site-packages\django\utils\functional.py", line 48, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "C:\Users\BB_SO\desktop\dev\Django_React\lib\site-packages\django\urls\resolvers.py", line 582, in urlconf_module
return import_module(self.urlconf_name)
File "C:\Users\BB_SO\anaconda3\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 728, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "C:\Users\BB_SO\desktop\dev\Django_React\music_site\music_site\urls.py", line 19, in <module>
urlpatterns = [path("admin/", admin.site.urls), path("", include("api.urls"))]
File "C:\Users\BB_SO\desktop\dev\Django_React\lib\site-packages\django\urls\conf.py", line 34, in include
urlconf_module = import_module(urlconf_module)
File "C:\Users\BB_SO\anaconda3\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 728, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "C:\Users\BB_SO\desktop\dev\Django_React\music_site\api\urls.py", line 2, in <module>
from .views import RoomView
File "C:\Users\BB_SO\desktop\dev\Django_React\music_site\api\views.py", line 3, in <module>
from .serlializer import RoomSerializer
ModuleNotFoundError: No module named 'api.serlializer'
Here my serializer.py file content:
from rest_framework import serializer
from .models import Room
class RoomSeralizer(seriarlizers.ModelSerializer):
class Meta:
model = Room
fields = (
"id",
"code",
"host",
"guest_can_pause",
"vote_to_skip",
"created_at",
)
Does anyone know what might be causing this error? I am still very new to coding and am using vscode if that helps at all. Thanks in advance for your help!
In serializer.py Try:
from rest_framework import serializers
Django-rest framework doesn't have any API called serializer.
More: https://www.django-rest-framework.org/api-guide/serializers/
import should be
from rest_framework import serializers

I'm trying to graphic with django using python but jump IndentationError: expected an indented block

Looks like simple but I'm starting code and I don't know what to do or why this error happened.
What I'm trying is to make an example graphic in django that's all not with success, all the information showed is confusing me.
this is my views.py
from django.shortcuts import render
import matplotlib.pyplot as plt
def home(request):
plt.plot(range(10))
return render(request, 'app1/home.html')
def about(request):
return render(request, 'app1/about.html', {'title': 'About'})
and jump the next error
Exception in thread django-main-thread:
Traceback (most recent call last):
File "/usr/lib/python3.9/threading.py", line 950, in _bootstrap_inner
self.run()
File "/usr/lib/python3.9/threading.py", line 888, in run
self._target(*self._args, **self._kwargs)
File "/home/corbin/ProyectoDB/venv/lib/python3.9/site-packages/django/utils/autoreload.py", line 53, in wrapper
fn(*args, **kwargs)
File "/home/corbin/ProyectoDB/venv/lib/python3.9/site-packages/django/core/management/commands/runserver.py", line 118, in inner_run
self.check(display_num_errors=True)
File "/home/corbin/ProyectoDB/venv/lib/python3.9/site-packages/django/core/management/base.py", line 392, in check
all_issues = checks.run_checks(
File "/home/corbin/ProyectoDB/venv/lib/python3.9/site-packages/django/core/checks/registry.py", line 70, in run_checks
new_errors = check(app_configs=app_configs, databases=databases)
File "/home/corbin/ProyectoDB/venv/lib/python3.9/site-packages/django/core/checks/urls.py", line 13, in check_url_config
return check_resolver(resolver)
File "/home/corbin/ProyectoDB/venv/lib/python3.9/site-packages/django/core/checks/urls.py", line 23, in check_resolver
return check_method()
File "/home/corbin/ProyectoDB/venv/lib/python3.9/site-packages/django/urls/resolvers.py", line 408, in check
for pattern in self.url_patterns:
File "/home/corbin/ProyectoDB/venv/lib/python3.9/site-packages/django/utils/functional.py", line 48, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/home/corbin/ProyectoDB/venv/lib/python3.9/site-packages/django/urls/resolvers.py", line 589, in url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "/home/corbin/ProyectoDB/venv/lib/python3.9/site-packages/django/utils/functional.py", line 48, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/home/corbin/ProyectoDB/venv/lib/python3.9/site-packages/django/urls/resolvers.py", line 582, in urlconf_module
return import_module(self.urlconf_name)
File "/usr/lib/python3.9/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 790, in exec_module
File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
File "/home/corbin/ProyectoDB/LabBD/Web_DB/urls.py", line 21, in <module>
path('', include('app1.urls')),
File "/home/corbin/ProyectoDB/venv/lib/python3.9/site-packages/django/urls/conf.py", line 34, in include
urlconf_module = import_module(urlconf_module)
File "/usr/lib/python3.9/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 790, in exec_module
File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
File "/home/corbin/ProyectoDB/LabBD/app1/urls.py", line 2, in <module>
from . import views
File "/home/corbin/ProyectoDB/LabBD/app1/views.py", line 11
^
IndentationError: expected an indented block
I will apreciate all your help.

Categories

Resources