I know before run the server i must be makemigrations but i can't i don't know so much python and django i can't migrate or makemigrations or runserver i tried specified for main app but still give me same error i write this 2 times nothing changed i try to make a price tracker for myself when i try makemigrations or runserver give me this error ;
File "C:\Users\KADAK\AppData\Local\Programs\Python\Python310\lib\site-packages\django\db\backends\utils.py", line 84, in _execute
return self.cursor.execute(sql, params)
File "C:\Users\KADAK\AppData\Local\Programs\Python\Python310\lib\site-packages\django\db\backends\sqlite3\base.py", line 383, in execute
return Database.Cursor.execute(self, query, params)
sqlite3.OperationalError: no such column: main_app_item.status
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\Users\KADAK\Desktop\Fiyat Takip\FiyatTakip\manage.py", line 21, in <module>
main()
File "C:\Users\KADAK\Desktop\Fiyat Takip\FiyatTakip\manage.py", line 17, in main
execute_from_command_line(sys.argv)
File "C:\Users\KADAK\AppData\Local\Programs\Python\Python310\lib\site-packages\django\core\management\__init__.py", line 381, in execute_from_command_line
utility.execute()
File "C:\Users\KADAK\AppData\Local\Programs\Python\Python310\lib\site-packages\django\core\management\__init__.py", line 375, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Users\KADAK\AppData\Local\Programs\Python\Python310\lib\site-packages\django\core\management\base.py", line 323, in run_from_argv
self.execute(*args, **cmd_options)
File "C:\Users\KADAK\AppData\Local\Programs\Python\Python310\lib\site-packages\django\core\management\base.py", line 361, in execute
self.check()
File "C:\Users\KADAK\AppData\Local\Programs\Python\Python310\lib\site-packages\django\core\management\base.py", line 387, in check
all_issues = self._run_checks(
File "C:\Users\KADAK\AppData\Local\Programs\Python\Python310\lib\site-packages\django\core\management\base.py", line 377, in _run_checks
return checks.run_checks(**kwargs)
File "C:\Users\KADAK\AppData\Local\Programs\Python\Python310\lib\site-packages\django\core\checks\registry.py", line 72, in run_checks
new_errors = check(app_configs=app_configs)
File "C:\Users\KADAK\AppData\Local\Programs\Python\Python310\lib\site-packages\django\core\checks\urls.py", line 13, in check_url_config
return check_resolver(resolver)
File "C:\Users\KADAK\AppData\Local\Programs\Python\Python310\lib\site-packages\django\core\checks\urls.py", line 23, in check_resolver
return check_method()
File "C:\Users\KADAK\AppData\Local\Programs\Python\Python310\lib\site-packages\django\urls\resolvers.py", line 403, in check
for pattern in self.url_patterns:
File "C:\Users\KADAK\AppData\Local\Programs\Python\Python310\lib\site-packages\django\utils\functional.py", line 80, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "C:\Users\KADAK\AppData\Local\Programs\Python\Python310\lib\site-packages\django\urls\resolvers.py", line 588, in url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "C:\Users\KADAK\AppData\Local\Programs\Python\Python310\lib\site-packages\django\utils\functional.py", line 80, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "C:\Users\KADAK\AppData\Local\Programs\Python\Python310\lib\site-packages\django\urls\resolvers.py", line 581, in urlconf_module
return import_module(self.urlconf_name)
File "C:\Users\KADAK\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\KADAK\Desktop\Fiyat Takip\FiyatTakip\FiyatTakip\urls.py", line 20, in <module>
from main_app.views import search
File "C:\Users\KADAK\Desktop\Fiyat Takip\FiyatTakip\main_app\views.py", line 56, in <module>
search_price()
File "C:\Users\KADAK\Desktop\Fiyat Takip\FiyatTakip\main_app\views.py", line 34, in search_price
for element in Item.objects.all():
File "C:\Users\KADAK\AppData\Local\Programs\Python\Python310\lib\site-packages\django\db\models\query.py", line 274, in __iter__
self._fetch_all()
File "C:\Users\KADAK\AppData\Local\Programs\Python\Python310\lib\site-packages\django\db\models\query.py", line 1242, in _fetch_all
self._result_cache = list(self._iterable_class(self))
File "C:\Users\KADAK\AppData\Local\Programs\Python\Python310\lib\site-packages\django\db\models\query.py", line 55, in __iter__
results = compiler.execute_sql(chunked_fetch=self.chunked_fetch, chunk_size=self.chunk_size)
File "C:\Users\KADAK\AppData\Local\Programs\Python\Python310\lib\site-packages\django\db\models\sql\compiler.py", line 1142, in execute_sql
cursor.execute(sql, params)
File "C:\Users\KADAK\AppData\Local\Programs\Python\Python310\lib\site-packages\django\db\backends\utils.py", line 99, in execute
return super().execute(sql, params)
File "C:\Users\KADAK\AppData\Local\Programs\Python\Python310\lib\site-packages\django\db\backends\utils.py", line 67, in execute
return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
File "C:\Users\KADAK\AppData\Local\Programs\Python\Python310\lib\site-packages\django\db\backends\utils.py", line 76, in _execute_with_wrappers
return executor(sql, params, many, context)
File "C:\Users\KADAK\AppData\Local\Programs\Python\Python310\lib\site-packages\django\db\backends\utils.py", line 80, in _execute
with self.db.wrap_database_errors:
File "C:\Users\KADAK\AppData\Local\Programs\Python\Python310\lib\site-packages\django\db\utils.py", line 89, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "C:\Users\KADAK\AppData\Local\Programs\Python\Python310\lib\site-packages\django\db\backends\utils.py", line 84, in _execute
return self.cursor.execute(sql, params)
File "C:\Users\KADAK\AppData\Local\Programs\Python\Python310\lib\site-packages\django\db\backends\sqlite3\base.py", line 383, in execute
return Database.Cursor.execute(self, query, params)
django.db.utils.OperationalError: no such column: main_app_item.status
so here my views.py ;
@login_required
def search(request):
if request.method == "POST":
item_url = request.POST.get("searchbox")
maximum_price = int(request.POST.get("max_price"))
if item_url != "" and maximum_price != "":
user = request.user
item_model = Item(user=user, url = item_url, max_price = maximum_price)
item_model.save()
return redirect('search')
return render(request, 'main_app/search.html')
def search_price():
max_price = 170
hdr= {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.109 Safari/537.36 OPR/84.0.4316.50'}
for element in Item.objects.all():
if element.status == False:
user = element.user
user_email = user.email
item_url = element.url
max_price = element.max_price
url = requests.get(str(item_url), headers=hdr)
soup = BeautifulSoup(url.content, 'html.parser')
price_span= soup.find('span', class_="price-current__amount").text[:3].split(',')
price =int("".join(price_span))
if price <= max_price:
subject = 'Ürününüz İndirime GİRDİ!!!'
message = f"Merhaba {user.username}, takip ettiğiniz ürün{item_url}, ayarladığınız fiyata geldi {price}"
email_from = settings.EMAIL_HOST_USER
recipient_list = [user_email]
send_mail(subject,message,email_from,recipient_list)
element.status = True
element.save()
search_price()
and this is my model.py ;
class Item(models.Model):
user = models.ForeignKey(User, on_delete=models.CASCADE)
url = models.CharField(max_length=700)
max_price = models.IntegerField()
status = models.BooleanField(default=False)
CodePudding user response:
Please comment out or remove search_price()
and try again for creating your migration files. Because you call this function on your module and since Django is instantiating this module, it'll always go through this function and since there isn't any status column yet, it can not create your migration file because it is failing in that module.
Change this part:
def search_price():
max_price = 170
hdr= {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.109 Safari/537.36 OPR/84.0.4316.50'}
for element in Item.objects.all():
if element.status == False:
user = element.user
user_email = user.email
item_url = element.url
max_price = element.max_price
url = requests.get(str(item_url), headers=hdr)
soup = BeautifulSoup(url.content, 'html.parser')
price_span= soup.find('span', class_="price-current__amount").text[:3].split(',')
price =int("".join(price_span))
if price <= max_price:
subject = 'Ürününüz İndirime GİRDİ!!!'
message = f"Merhaba {user.username}, takip ettiğiniz ürün{item_url}, ayarladığınız fiyata geldi {price}"
email_from = settings.EMAIL_HOST_USER
recipient_list = [user_email]
send_mail(subject,message,email_from,recipient_list)
element.status = True
element.save()
search_price()
to:
def search_price():
max_price = 170
hdr= {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.109 Safari/537.36 OPR/84.0.4316.50'}
for element in Item.objects.all():
if element.status == False:
user = element.user
user_email = user.email
item_url = element.url
max_price = element.max_price
url = requests.get(str(item_url), headers=hdr)
soup = BeautifulSoup(url.content, 'html.parser')
price_span= soup.find('span', class_="price-current__amount").text[:3].split(',')
price =int("".join(price_span))
if price <= max_price:
subject = 'Ürününüz İndirime GİRDİ!!!'
message = f"Merhaba {user.username}, takip ettiğiniz ürün{item_url}, ayarladığınız fiyata geldi {price}"
email_from = settings.EMAIL_HOST_USER
recipient_list = [user_email]
send_mail(subject,message,email_from,recipient_list)
element.status = True
element.save()
# search_price() --> here you are calling this function which is the
# main reason of your error. So this line should be removed.