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.
Related
I've 3 pages Model, Forms and View
In model.py i define my table
#model.py
class Prod(models.Model):
id = models.CharField(primary_key=True, max_length=10, blank=False, null=False)
description = models.TextField(blank=True, null=True)
class Meta:
managed = False
db_table = 'product'
verbose_name = 'PROD'
now I move to forms.py
#forms.py
from .models import Prod
class ProdForm(forms.ModelForm):
#some code to fill
class Meta:
model = Prod
exclude = [...]
widgets = {
...
}
labels = {
...
}
and finally with view.py
#view.py
from .forms import ProdForm
When i execute python manage.py makemigrations, I get an error saying
no such table: product
my app was hosting locally with postgres, now i used db.sqlite3 to test, i don't undestand why views.py can't import the table forms or at least why It's not creating them?
I don't understand why, specially that this code was running locally with a postgres.
traceback:
Traceback (most recent call last):
File "C:\APP\envs\.webdev\lib\site-packages\django\db\backends\utils.py", line 84, in _execute
return self.cursor.execute(sql, params)
File "C:\APP\envs\.webdev\lib\site-packages\django\db\backends\sqlite3\base.py", line 423, in execute
return Database.Cursor.execute(self, query, params)
sqlite3.OperationalError: no such table: product
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\TR v2 arz\alpha_arz_apps\manage.py", line 22, in <module>
main()
File "C:\TR v2 arz\alpha_arz_apps\manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "C:\APP\envs\.webdev\lib\site-packages\django\core\management\__init__.py", line 419, in execute_from_command_line
utility.execute()
File "C:\APP\envs\.webdev\lib\site-packages\django\core\management\__init__.py", line 413, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\APP\envs\.webdev\lib\site-packages\django\core\management\base.py", line 354, in run_from_argv
self.execute(*args, **cmd_options)
File "C:\APP\envs\.webdev\lib\site-packages\django\core\management\base.py", line 393, in execute
self.check()
File "C:\APP\envs\.webdev\lib\site-packages\django\core\management\base.py", line 419, in check
all_issues = checks.run_checks(
File "C:\APP\envs\.webdev\lib\site-packages\django\core\checks\registry.py", line 76, in run_checks
new_errors = check(app_configs=app_configs, databases=databases)
File "C:\APP\envs\.webdev\lib\site-packages\django\core\checks\urls.py", line 13, in check_url_config
return check_resolver(resolver)
File "C:\APP\envs\.webdev\lib\site-packages\django\core\checks\urls.py", line 23, in check_resolver
return check_method()
File "C:\APP\envs\.webdev\lib\site-packages\django\urls\resolvers.py", line 412, in check
for pattern in self.url_patterns:
File "C:\APP\envs\.webdev\lib\site-packages\django\utils\functional.py", line 48, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "C:\APP\envs\.webdev\lib\site-packages\django\urls\resolvers.py", line 598, in url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "C:\APP\envs\.webdev\lib\site-packages\django\utils\functional.py", line 48, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "C:\APP\envs\.webdev\lib\site-packages\django\urls\resolvers.py", line 591, in urlconf_module
return import_module(self.urlconf_name)
File "C:\Users\amq.o\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:\TR v2 arz\alpha_arz_apps\alpha_arz_apps\urls.py", line 23, in <module>
path('TR/', include('TR.urls')),
File "C:\APP\envs\.webdev\lib\site-packages\django\urls\conf.py", line 34, in include
urlconf_module = import_module(urlconf_module)
File "C:\Users\amq.o\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:\TR v2 arz\alpha_arz_apps\TR\urls.py", line 3, in <module>
import TR.views as views
File "C:\TR v2 arz\alpha_arz_apps\TR\views.py", line 14, in <module>
from .forms import ProdForm
File "C:\TR v2 arz\alpha_arz_apps\TR\forms.py", line 50, in <module>
class ProdForm(forms.ModelForm):
File "C:\TR v2 arz\alpha_arz_apps\TR\forms.py", line 55, in ProdForm
desc = list(Prod.objects.all().values_list('description', flat=True).distinct().order_by('channel'))
File "C:\APP\envs\.webdev\lib\site-packages\django\db\models\query.py", line 262, in __len__
self._fetch_all()
File "C:\APP\envs\.webdev\lib\site-packages\django\db\models\query.py", line 1324, in _fetch_all
self._result_cache = list(self._iterable_class(self))
File "C:\APP\envs\.webdev\lib\site-packages\django\db\models\query.py", line 171, in __iter__
for row in compiler.results_iter(chunked_fetch=self.chunked_fetch, chunk_size=self.chunk_size):
File "C:\APP\envs\.webdev\lib\site-packages\django\db\models\sql\compiler.py", line 1130, in results_iter
results = self.execute_sql(MULTI, chunked_fetch=chunked_fetch, chunk_size=chunk_size)
File "C:\APP\envs\.webdev\lib\site-packages\django\db\models\sql\compiler.py", line 1175, in execute_sql
cursor.execute(sql, params)
File "C:\APP\envs\.webdev\lib\site-packages\django\db\backends\utils.py", line 98, in execute
return super().execute(sql, params)
File "C:\APP\envs\.webdev\lib\site-packages\django\db\backends\utils.py", line 66, in execute
return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
File "C:\APP\envs\.webdev\lib\site-packages\django\db\backends\utils.py", line 79, in _execute
with self.db.wrap_database_errors:
File "C:\APP\envs\.webdev\lib\site-packages\django\db\utils.py", line 90, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "C:\APP\envs\.webdev\lib\site-packages\django\db\backends\utils.py", line 84, in _execute
return self.cursor.execute(sql, params)
File "C:\APP\envs\.webdev\lib\site-packages\django\db\backends\sqlite3\base.py", line 423, in execute
return Database.Cursor.execute(self, query, params)
django.db.utils.OperationalError: no such table: product
Remove the ProdForm definition from forms.py
Call python manage.py makemigrations
Call python manage.py migrate
Add form back into forms.py
Note: Always migrate your new model definitions before using them as a dependency
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
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.
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)
I have a problem with my Django app, I removed my products app for more practicing and when I use migrate or makemigrations code, I get this error:
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\clpxv\Desktop\Projects\venv\lib\site-packages\django\core\management\__init__.py", line 401, in execute_from_command_line
utility.execute()
File "C:\Users\clpxv\Desktop\Projects\venv\lib\site-packages\django\core\management\__init__.py", line 395, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Users\clpxv\Desktop\Projects\venv\lib\site-packages\django\core\management\base.py", line 330, in run_from_argv
self.execute(*args, **cmd_options)
File "C:\Users\clpxv\Desktop\Projects\venv\lib\site-packages\django\core\management\base.py", line 371, in execute
output = self.handle(*args, **options)
File "C:\Users\clpxv\Desktop\Projects\venv\lib\site-packages\django\core\management\base.py", line 85, in wrapped
res = handle_func(*args, **kwargs)
File "C:\Users\clpxv\Desktop\Projects\venv\lib\site-packages\django\core\management\commands\migrate.py", line 75, in handle
self.check(databases=[database])
File "C:\Users\clpxv\Desktop\Projects\venv\lib\site-packages\django\core\management\base.py", line 392, in check
all_issues = checks.run_checks(
File "C:\Users\clpxv\Desktop\Projects\venv\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\clpxv\Desktop\Projects\venv\lib\site-packages\django\core\checks\urls.py", line 13, in check_url_config
return check_resolver(resolver)
File "C:\Users\clpxv\Desktop\Projects\venv\lib\site-packages\django\core\checks\urls.py", line 23, in check_resolver
return check_method()
File "C:\Users\clpxv\Desktop\Projects\venv\lib\site-packages\django\urls\resolvers.py", line 408, in check
for pattern in self.url_patterns:
File "C:\Users\clpxv\Desktop\Projects\venv\lib\site-packages\django\utils\functional.py", line 48, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "C:\Users\clpxv\Desktop\Projects\venv\lib\site-packages\django\urls\resolvers.py", line 589, in url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "C:\Users\clpxv\Desktop\Projects\venv\lib\site-packages\django\utils\functional.py", line 48, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "C:\Users\clpxv\Desktop\Projects\venv\lib\site-packages\django\urls\resolvers.py", line 582, in urlconf_module
return import_module(self.urlconf_name)
File "C:\Users\clpxv\AppData\Local\Programs\Python\Python38-32\lib\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 "C:\Users\clpxv\Desktop\Projects\Projects\urls.py", line 15, in <module>
o
NameError: name 'o' is not defined
I don't have any idea what is this, I didn't change anything in os or anything else.
I will be grateful for a simple answer.
You have typed 'o' in urls.py line 15 just remove and save the file and delete migration file and again migrate all details