return Database.Cursor.execute(self, query, params)django.db.utils.OperationalError: no such column
return Database.Cursor.execute(self, query, params)django.db.utils.OperationalError: no such column
我之前知道 运行 服务器我必须是 makemigrations 但我不能 我不太了解 python 和 django 我不能迁移或 makemigrations 或 运行服务器我尝试为主要应用程序指定但仍然给我同样的错误我写了2次没有改变我尝试为自己制作价格跟踪器当我尝试makemigrations或运行服务器给我这个错误;
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
所以我的 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()
这是我的 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)
请注释掉或删除 search_price()
,然后重试创建迁移文件。因为你在你的模块上调用了这个函数,并且因为 Django 正在实例化这个模块,所以它总是会通过这个函数并且因为还没有任何状态列,它不能创建你的迁移文件,因为它在那个模块中失败了。
更改此部分:
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()
至:
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.
我之前知道 运行 服务器我必须是 makemigrations 但我不能 我不太了解 python 和 django 我不能迁移或 makemigrations 或 运行服务器我尝试为主要应用程序指定但仍然给我同样的错误我写了2次没有改变我尝试为自己制作价格跟踪器当我尝试makemigrations或运行服务器给我这个错误;
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
所以我的 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()
这是我的 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)
请注释掉或删除 search_price()
,然后重试创建迁移文件。因为你在你的模块上调用了这个函数,并且因为 Django 正在实例化这个模块,所以它总是会通过这个函数并且因为还没有任何状态列,它不能创建你的迁移文件,因为它在那个模块中失败了。
更改此部分:
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()
至:
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.