问题
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.
回答1:
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)
来源:https://stackoverflow.com/questions/65739543/migrations-are-not-taking-place-after-pushing-my-code-on-heroku