Django community: RSS
This page, updated regularly, aggregates Django Q&A from the Django community.
-
Render different template depending on object class
I have a sorted list with items of three different types. Two are of the same class: q1 = Model1.objects.annotate(created_at=F('created')) q2 = Model2.objects.annotate(created_at=F('creation_datetime')) items = sorted(chain(q1, q2), key=attrgetter('created_at'), reverse=True) Then in the list template: {% for item in items %} ??? {% endfor %} Items of class Model1 should use template1.html, items of Model2 and type X template2X.htmland items of Model2 and type Y template2Y.html. I have thought of the following terrible idea: rendering the template in a tag. @register.assignment_tag(takes_context=True) def render_item(context, item): if isinstance(item, Model1): return render_to_string('template1.html', context) elif isinstance(item, Model2): if item.typeX: return render_to_string('template2X.html', context) elif item.typeY: return render_to_string('template2Y.html', context) return render_to_strong('unknown.html', context) And then: {% for item in items %} {% render_item item as html %} {{ html }} {% endfor %} What's the appropriate way to do this? -
how to solve django HayStack, elasticsearch update_index error?
i integrated elasticsearch and haystack using django web framework. now i want remove non existed data from elasticsearch index using call_command('update_index --remove') function . my problem is when i run update_index --remove i produce following error : Indexing 6 notes [ERROR/MainProcess] Error updating core using default Traceback (most recent call last): File "/usr/local/lib/python3.6/dist-packages/haystack/management/commands/update_index.py", line 230, in handle self.update_backend(label, using) File "/usr/local/lib/python3.6/dist-packages/haystack/management/commands/update_index.py", line 308, in update_backend index_total = SearchQuerySet(using=backend.connection_alias).models(model).count() File "/usr/local/lib/python3.6/dist-packages/haystack/query.py", line 522, in count return len(self) File "/usr/local/lib/python3.6/dist-packages/haystack/query.py", line 86, in __len__ self._result_count = self.query.get_count() File "/usr/local/lib/python3.6/dist-packages/haystack/backends/__init__.py", line 619, in get_count self.run() File "/usr/local/lib/python3.6/dist-packages/haystack/backends/elasticsearch_backend.py", line 951, in run results = self.backend.search(final_query, **search_kwargs) File "/usr/local/lib/python3.6/dist-packages/haystack/backends/__init__.py", line 33, in wrapper return func(obj, query_string, *args, **kwargs) File "/usr/local/lib/python3.6/dist-packages/haystack/backends/elasticsearch_backend.py", line 524, in search _source=True) File "/usr/local/lib/python3.6/dist-packages/elasticsearch/client/utils.py", line 84, in _wrapped return func(*args, params=params, **kwargs) TypeError: search() got an unexpected keyword argument 'doc_type' Traceback (most recent call last): File "manage.py", line 15, in <module> execute_from_command_line(sys.argv) File "/usr/local/lib/python3.6/dist-packages/django/core/management/__init__.py", line 381, in execute_from_command_line utility.execute() File "/usr/local/lib/python3.6/dist-packages/django/core/management/__init__.py", line 375, in execute self.fetch_command(subcommand).run_from_argv(self.argv) File "/usr/local/lib/python3.6/dist-packages/django/core/management/base.py", line 316, in run_from_argv self.execute(*args, **cmd_options) File "/usr/local/lib/python3.6/dist-packages/django/core/management/base.py", line 353, in execute output = self.handle(*args, **options) File "/usr/local/lib/python3.6/dist-packages/haystack/management/commands/update_index.py", line 230, in handle self.update_backend(label, using) File "/usr/local/lib/python3.6/dist-packages/haystack/management/commands/update_index.py", line 308, in update_backend index_total = SearchQuerySet(using=backend.connection_alias).models(model).count() File … -
Django warnings during POST
after submiting form and POST method I have warnings in my console, and I don't know what to fix. Any idea? [19/Dec/2019 12:13:25] "GET /scenario/14/ HTTP/1.1" 200 7573 C:\django\ENV\lib\site-packages\django\db\models\fields\__init__.py:1364: RuntimeWarning: DateTimeField Comment.commentDate received a naive datetime (2019-12-19 12:13:28.699121) while time zone support is active. RuntimeWarning) Internal Server Error: /comment/14/ Traceback (most recent call last): File "C:\django\ENV\lib\site-packages\django\views\generic\edit.py", line 116, in get_success_url url = self.object.get_absolute_url() AttributeError: 'Comment' object has no attribute 'get_absolute_url' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "C:\django\ENV\lib\site-packages\django\core\handlers\exception.py", line 34, in inner response = get_response(request) File "C:\django\ENV\lib\site-packages\django\core\handlers\base.py", line 115, in _get_response response = self.process_exception_by_middleware(e, request) File "C:\django\ENV\lib\site-packages\django\core\handlers\base.py", line 113, in _get_response response = wrapped_callback(request, *callback_args, **callback_kwargs) File "C:\django\ENV\lib\site-packages\django\views\generic\base.py", line 71, in view return self.dispatch(request, *args, **kwargs) File "C:\django\ENV\lib\site-packages\django\contrib\auth\mixins.py", line 52, in dispatch return super().dispatch(request, *args, **kwargs) File "C:\django\ENV\lib\site-packages\django\views\generic\base.py", line 97, in dispatch return handler(request, *args, **kwargs) File "C:\django\ENV\lib\site-packages\django\views\generic\edit.py", line 172, in post return super().post(request, *args, **kwargs) File "C:\django\ENV\lib\site-packages\django\views\generic\edit.py", line 142, in post return self.form_valid(form) File "C:\django\m\testmanager\views.py", line 58, in form_valid return super().form_valid(form) File "C:\django\ENV\lib\site-packages\django\views\generic\edit.py", line 126, in form_valid return super().form_valid(form) File "C:\django\ENV\lib\site-packages\django\views\generic\edit.py", line 57, in form_valid return HttpResponseRedirect(self.get_success_url()) File "C:\django\ENV\lib\site-packages\django\views\generic\edit.py", line 119, in get_success_url "No URL to redirect to. Either provide a … -
Django call_command() not running external command
I am unable to run a command that runs an external script using call_command() Here is my code: from django.core import management @login_required def play_redirect(request): management.call_command('runscript', 'runnerscript') return HttpResponse('Please wait while we redirect you...') runscript is a special command obtained from django-extensions module and it runs a script that has a game made in vpython, but everytime i run this I get a RuntimeError related to a thread. Here is the exact Error: RuntimeError at /bloxors/play/ There is no current event loop in thread 'Thread-1'. Request Method: GET Request URL: http://127.0.0.1:8000/bloxors/play/ Django Version: 2.2.2 Exception Type: RuntimeError Exception Value: There is no current event loop in thread 'Thread-1'. Exception Location: C:\Users\Dps\AppData\Local\Programs\Python\Python37-32\lib\asyncio\events.py in get_event_loop, line 644 Python Executable: C:\Users\Dps\AppData\Local\Programs\Python\Python37-32\python.exe Python Version: 3.7.2 Python Path: ['C:\\Users\\Dps\\Desktop\\bloxnsims\\website', 'C:\\Users\\Dps\\AppData\\Local\\Programs\\Python\\Python37-32\\python37.zip', 'C:\\Users\\Dps\\AppData\\Local\\Programs\\Python\\Python37-32\\DLLs', 'C:\\Users\\Dps\\AppData\\Local\\Programs\\Python\\Python37-32\\lib', 'C:\\Users\\Dps\\AppData\\Local\\Programs\\Python\\Python37-32', 'C:\\Users\\Dps\\AppData\\Local\\Programs\\Python\\Python37-32\\lib\\site-packages', 'C:\\Users\\Dps\\AppData\\Local\\Programs\\Python\\Python37-32\\lib\\site-packages\\win32', 'C:\\Users\\Dps\\AppData\\Local\\Programs\\Python\\Python37-32\\lib\\site-packages\\win32\\lib', 'C:\\Users\\Dps\\AppData\\Local\\Programs\\Python\\Python37-32\\lib\\site-packages\\Pythonwin'] Any possible help on this is greatly appreciated! -
Foreign Key Constraint failed when using custom signup form in django-allauth
I am using a custom user model and I have set mobile number as my identifier. The model looks like this. from django.contrib.auth.models import ( BaseUserManager, AbstractBaseUser ) # Create your models here. class UserManager(BaseUserManager): def create_user(self, mobile_number, password=None): """ Creates and saves a User with the given email and password. """ if not mobile_number: raise ValueError('Users must have an mobile number') user = self.model( mobile_number = mobile_number, ) user.set_password(password) user.save(using=self._db) return user def create_staffuser(self, mobile_number, password): """ Creates and saves a staff user with the given email and password. """ user = self.create_user( mobile_number = mobile_number, password=password, ) user.staff = True user.save(using=self._db) return user def create_superuser(self, mobile_number, password): """ Creates and saves a superuser with the given email and password. """ user = self.create_user( mobile_number = mobile_number, password=password, ) user.staff = True user.admin = True user.save(using=self._db) return user class User(AbstractBaseUser): email = models.EmailField( verbose_name='email address', max_length=255, blank=True, null=True, ) mobile_number = models.CharField(max_length= 11,unique=True) active = models.BooleanField(default=True) staff = models.BooleanField(default=False) # a admin user; non super-user admin = models.BooleanField(default=False) # a superuser username = models.CharField(max_length=40, unique=True,blank=True,null=True) # notice the absence of a "Password field", that's built in. USERNAME_FIELD = 'mobile_number' REQUIRED_FIELDS = [] # Email & Password are required by … -
Django - how to do an aggregation inside annotation
My models are the following: class Content(models.Model): user = models.ForeignKey(User, on_delete=models.CASCADE, null=True) second_contents = models.ManyToManyField('self', related_name='first_contents', blank=True) class Fight(models.Model): win_content = models.ForeignKey(Content, db_index=True, on_delete=models.SET_NULL, related_name="wins", null=True) loss_content = models.ForeignKey(Content, db_index=True, on_delete=models.SET_NULL, related_name="losses", null=True) user = models.ForeignKey(User, db_index=True, related_name="clashes", on_delete=models.SET_NULL, blank=True, null=True) timestamp = models.DateTimeField(auto_now_add=True) class Hashtag(models.Model): hashtag = models.CharField(db_index=True, max_length=50, null=False, unique=True) contents = models.ManyToManyField(Content, db_index=True, related_name="hashtags", blank=True) Each Content in Content.second_contents builds a Pair of two contents. Each Content can have n second_contents One Pair Result is defined as one Fight object containing both Pair Content objects as win_content and loss_content. Now let's say I have a Hashtag object with 10000 Content objects as Hashtag.contents. I want to get the top100 Pair of Contents which have the most Results, so in the end I'm looking the get some order_by Queryset with an annotated item count. What I've tried: contents = (Content.objects .filter(hashtags__in=hashtagid) .filter(first_contents__in=contents) .annotate( count="""some query like max(count(wins, filter=Q(second_contents__in=F('content'))) + count(losses, filter=Q(second_contents__in=F('content'))))""" ) .order_by('count')[:100] ) Is there any way to perform that query as an annotation? e.g. loop through each Content.second_contents relationship, count the number of wins and losses, and finally annotate the Max value? I'm kind of stuck with my current knowledge of possible queries and can't see … -
Django - Form template throws "This field is required" for Imagefield
I'm having some trouble with image upload in Django 3.0. I'm experiencing the issue where trying to upload an image from my template throws the error "This field is required" even though i have a file selected. It uploads fine I do it from the form in the admin area. models.py class Image(models.Model): title = models.CharField(max_length=50) image = models.ImageField(upload_to='images/') def __str__(self): return self.title views.py def new_post_view(request): new_img = ImageForm(request.POST or None) if new_img.is_valid(): new_img.save() new_img = ImageForm() return redirect('imageposts:gallery') return render(request, 'imageposts/create.html', {'new_pic': new_img}) forms.py class ImageForm(forms.ModelForm): class Meta: model = Image fields = [ "title", "image", ] widgets = { "title": forms.TextInput(), "image": forms.FileInput(), } create.html {% extends 'base.html' %} {% block content %} <form method="post" enctype="multipart/form-data"> {% csrf_token %} {{new_pic.as_p}} <button type="submit">Add image</button> </form> {% endblock %} Solutions i've seen have been to make the field nullable and empty, but for this case, the image is an always required, but it's just not uploading the selected file. The form just clears the file section and throws "This field is required." I've tried in both django 3.0 and django 2.2 and I get the same result. I can't tell what it is I'm doing wrong here, and would appreciate … -
Filter a queryset by a list of users and request.user at the same time
I would like to create a queryset containing posts from both a list of 'friends' and 'request.user'. So far I can only filter posts by friends using posts = Post.objects.filter(user__in=friends). I tried to do posts = Post.objects.filter(user__in=friends).filter(user=request.user) but this returns an empty queryset. I can't figure out how to filter 'posts' using both parameters at the same time. Any suggestions would be much appreciated, cheers. -
Django website stop working for some wrong time on clock issue
Look this Divio is cool and all but my website stop working. I mean is it about the hosting problem or is it problem with website code or what? it says i have wrong time on clock and browser doesn't let me visit site what happened? https://imgur.com/9S0bpUe the platform it is on is us.aldryn.io from divio i spent whole day mastering it and then this happen -
Django & intercooler.js : Pass a variable to a view with Intercooler.js
I am trying to integrate intercooler.js (https://intercoolerjs.org) to my project but failing at passing a variable from the template into a view. Any help would be appreciated. I got as far as this: (a) the template: <form id="defaults"> <input name="csrfmiddlewaretoken" type="hidden" value="{{ csrf_token }}"> </form> <button ic-post-to="{% url 'habitap:click' %}?click_value={{clicks}}" ic-include="#defaults"> {{clicks}} </button> (b) the view def click(request): clicks = request.POST.get('click_value', 0) clicks = clicks + 1 context = {'clicks': clicks} template = Template("{{clicks}}") request_context = RequestContext(request, context) return HttpResponse(template.render(request_context)) Thank you, Ben -
Django - Import Export - Process data before saving it to database
I have an excel sheet that looks like this: I want to store the data in this model: class ExcelData(models.Model): var1 = models.CharField(max_length=200) var2 = models.CharField(max_length=200) var3 = models.CharField(max_length=200) var4 = models.IntegerField() This is how far I got: @admin.register(ExcelData) class ViewAdmin(ImportExportModelAdmin): fields = ( "var1", "var2", "var3", "var4" ) class ExcelDataResource(resources.ModelResource): var1 = Field(attribute='var1', column_name='Name') var2 = Field(attribute='var2', column_name='SAP_ID') var3 = Field(attribute='var3', column_name='Abbreviation') var4 = Field(attribute='var4', column_name='Max_Capacity') class Meta: model = ExcelData import_id_fields = ('Name',) I get this error: Column 'id' not found in dataset. Available columns are: ['Name', 'SAP_ID', 'Abbrev.', 'Max. Capacity'] Thank you for any suggestions -
How to change dynamically attachment file name in django CSV export?
I Added static file name manju.csv but I want assign variable to filename like today date. Please help me def district_wise_download(request): from_date = request.GET.get('from_date') to_date = request.GET.get('to_date') district = request.GET.get('district') print(district) if 'district' in request.GET: new_from = datetime.datetime.strptime(from_date, '%Y-%m-%d').date() new_to = datetime.datetime.strptime(to_date, '%Y-%m-%d').date() min_dt = datetime.datetime.combine(new_from, datetime.time.min) max_dt = datetime.datetime.combine(new_to, datetime.time.max) download_district = All_enquiries.objects.filter(Q(enquired_at__range = (min_dt, max_dt))&Q(district=district)) response = HttpResponse(content_type='text/csv') response['Content-Disposition'] = 'attachment; filename="manju.csv"' writer = csv.writer(response, delimiter=',') writer.writerow(['created_at','product_name','product_category','price','customer_name','customer_mobile','state','district','city','pincode','status','remarks','source','username']) for obj in download_district: writer.writerow([obj.enquired_at,obj.product_name,obj.product_category,obj.price,obj.customer_name,obj.customer_mobile,obj.state,obj.district,obj.city,obj.pincode,obj.status,obj.remarks,obj.get_source_display(),obj.user_id]) return response -
putting a pandas dataframe inside a django template
I want to put a pandas dataframe inside a django template. For instance I want something like this: <html> <head><title>HTML Pandas Dataframe with CSS</title></head> <body> THE PANDAS DATAFRAME </body> </html> What I have tried are these codes. First in my django views.py, this was my function: from django.shortcuts import render import pandas as pd def about(request): df = pd.DataFrame({'a': [12, 3, 4], 'b': [5, 6, 7]}) df = df.to_html(classes='mystyle') return render(request, 'blog/about.html', {'table': df}) The template is: {% load static %} <link rel="stylesheet" type="text/css" href="{% static 'blog/style.css' %}"> <html> <head><title>HTML Pandas Dataframe with CSS</title></head> <body> {{table}} </body> </html> And, the style.css is: body { background: black; color: white; } Apparently, when I check it in my browser the template is loaded with the CSS code correctly but it gives me the following output instead of the table that I want: <table border="1" class="dataframe mystyle"> <thead> <tr style="text-align: right;"> <th></th> <th>a</th> <th>b</th> </tr> </thead> <tbody> <tr> <th>0</th> <td>12</td> <td>5</td> </tr> <tr> <th>1</th> <td>3</td> <td>6</td> </tr> <tr> <th>2</th> <td>4</td> <td>7</td> </tr> </tbody> </table> I am new to django, so maybe my approach is completely wrong. -
When a superuser logs in, check if a model object exists, if not, redirect to creation
Consider a model called AppSettings. Let's say the project has recently been installed on a server and I want to make it so that whenever a superuser logs in, before adding any other model objects or doing anything else, I want to first check if there's an AppSettings object. If there isn't I want to immediately redirect to the AppSettings add form and allow actions after there's at least one object. There would be a auto_add datetime field called "last_update" so we can check for the last object by doing AppSettings.objects.latest("last_update"). I just want to know how to check and redirect and where to put that code or any other way to achieve my goal. Thank you for your time, I appreciate it. -
Own django framework
I have idea to create my own framework use it in following new projects - just get out already realised tools. How to better create framework, can you give me some advices? -
Error when tring to makemigrations in djnago
I'm tring to add tags functionality to my django aplication. I want to use taggit app, but when I try to makemigrations I am getting an error: from django.db.models.fields.related import (add_lazy_relation, ManyToManyRel, ImportError: cannot import name 'add_lazy_relation' from taggit.managers import TaggableManager class Post(models.Model): tags = TaggableManager() I'm using: Django==2.2.8, django-taggit==0.17.1 -
List of current user objects in Django ListView
I want to render list of all objects on my template, wich their author is current logged user. I passed the username of current user to url.py: <a href="{% url 'myscenarios' user.username %}">My List</a> My urls.py: path('myscenarios/<str:username>/', MyScenarioListView.as_view(), name='myscenarios'), My question is how to build the queryset in views.py and what to type in template block in my html? class MyScenarioListView(LoginRequiredMixin, ListView): model = Scenario template_name = 'testmanager/myscenarios.html' context_object_name = 'myscenarios' def get_queryset(self): user = get_object_or_404(User, username=self.kwargs.get('username')) return Scenario.objects.filter(scenarioAuthor = user).order_by('-date_posted') What code shoud I type in my myscenarios.html file? -
How to convert with annotate String to Bool with Django ORM
My question is as follows. There is a request Thread.objects.all().annotate(is_marked=Count('mark', Q(mark__username='gou'))) in SQL it looks like this SELECT "api_thread"."id", "api_thread"."conference_id", "api_thread"."title", "api_thread"."description", "api_thread"."is_closed", "api_thread"."is_hidden", "api_thread"."is_pinned", "api_thread"."has_voting", "api_thread"."creator_uid", "api_thread"."created_at", "api_thread"."expired", COUNT("api_thread_mark"."user_id") FILTER (WHERE "auth_user"."username" = 'gou') AS "is_marked" FROM "api_thread" LEFT OUTER JOIN "api_thread_mark" ON ("api_thread"."id" = "api_thread_mark"."thread_id") LEFT OUTER JOIN "auth_user" ON ("api_thread_mark"."user_id" = "auth_user"."id") GROUP BY "api_thread"."id" What do I need to do to turn a number into an boolean. In SQL it look like COUNT("api_thread_mark"."user_id") FILTER (WHERE "auth_user"."username" = 'gou') > 0 AS "is_marked" -
How to provide validation for the users model in views itself in django(not the custom user model)?
I am having user model in the models.py and the every user even the repeated user emails and usernames are being stored in the database but I need the validation of email and password upto 8 characters in the views.py My models.py is class users(models.Model): email=models.CharField(max_length=50,default='0000000') password=models.CharField(max_length=50,default='0000000') room = models.ForeignKey(rooms,on_delete=models.CASCADE) goal = models.ManyToManyField(goals) style = models.ManyToManyField(designs) My views.py def user_register(request): if request.method == 'POST': email = request.POST['email'] password = request.POST['password'] room = request.POST['room'] g=goal=request.POST['goal'] g = g.split(',') s=style=request.POST['style'] s=s.split(',') user = users(password=password,email=email) user.room=rooms.objects.get(pk=room) goal = goals.objects.filter(pk__in=g) style = designs.objects.filter(pk__in=s) user.save() user.goal.add(*goal) user.style.add(*style) return render(request,'home.html') -
How i can structure a web application that uses django-rest-framework [closed]
I have been working with django-rest-framework for some time now, building small applications. I now have a big application coming up to develop. I'm planning to use django-rest-framework, but I would like to know what best practices, if any, exist to structure a big project. Thanks in advance for your feedback. -
I succesfully hosted my django app in digital ocean. Later, the app is not available in the ip address [closed]
I followed the docs of digitalocean to host my django app. After spending hours on the same, i was able to host. But the next day when I checked the ip address, it is not available. Also, I cannot ssh remotely. The only way to login is the web console from the digital ocean site. When I ssh remotely i get this error : ssh: connect to host 139.59.24.133 port 22: Connection timed out I reboot the droplet and it did not help. -
HTTP GET request with django-pytest client
In on of my view tests, I tried to make a simple get request that requires Basic Auth using a client: staff_credentials = base64.b64encode(b'staff_user:staff_password').decode('utf-8') response = client.get(url, headers={ "Authorization": f"Basic {staff_credentials}" }) assert response.status_code == 200 But I keep getting a 401 response corresponding to an Unauthorized access. Is there any problem with my method? Thanks. -
manipulation the original source of a file or video url like youtube player or cloud file download sites
if we see big websites like youtube, google drive, facebook, cloud file download sites, etc., then we will find that every link file, video, image or whatever, then the original file link will not be seen for example videos on youtube, even if we inspect the element and see the source on the video player it isn't visible, the link is just written: src = "https://www.youtube.com/94118230-9dbf-4207-a098-de7a7ccdf7f6" without any real address or file extension like .mp4 or others. can anyone help explain how to engineer this and whether django can handle engineering like this? -
Django - Display a loading message, popup, screen or icon when clicking a button in form
I have a very simple form: <form action="{% url 'test' %}" method="post"> {% csrf_token %} <div class="col-md-12"> {{ form }} <div class="row"> <input class="btn btn-primary" type="submit" value="Compute"> </div> </div> </form> When I click this button, depending on the "type" of call, it can takes up to 20 seconds (due to the SQL queries being called) Is there a way in pure django / python (please no jQuery, as I try to keep this as simple as possible) to display anything on the page after clicking the button and until the message is a success ? Find below my very simple form: class TestForm(forms.Form): option1 = forms.BooleanField(label="By XYZ", required=False) option2 = forms.BooleanField(label="By ZYX", required=False) error_messages = { 'no_option': "Please select at least one of the options." } Note that I also use messages.success(request, f"Successfully computed values") which means, somehow the application is aware when the call has ended -
Error While running migrate command in Django with Postgresql database
I'm working on a django project with Django 2.2 and Postgresql 10.11 as database with latest version of psycopg2. But when I run migrate command, below error happen for specific migration. Running migrations: Applying panelprofile.0003_auto_20191007_1700...Traceback (most recent call last): File "manage.py", line 21, in <module> main() File "manage.py", line 17, in main execute_from_command_line(sys.argv) File "C:\Users\Pouya\Desktop\programs\python\marketpine-backend\venv\lib\site-packages\django\core\management\__init__.py", line 381, in execute_from_command_line utility.execute() File "C:\Users\Pouya\Desktop\programs\python\marketpine-backend\venv\lib\site-packages\django\core\management\__init__.py", line 375, in execute self.fetch_command(subcommand).run_from_argv(self.argv) File "C:\Users\Pouya\Desktop\programs\python\marketpine-backend\venv\lib\site-packages\django\core\management\base.py", line 323, in run_from_argv self.execute(*args, **cmd_options) File "C:\Users\Pouya\Desktop\programs\python\marketpine-backend\venv\lib\site-packages\django\core\management\base.py", line 364, in execute output = self.handle(*args, **options) File "C:\Users\Pouya\Desktop\programs\python\marketpine-backend\venv\lib\site-packages\django\core\management\base.py", line 83, in wrapped res = handle_func(*args, **kwargs) File "C:\Users\Pouya\Desktop\programs\python\marketpine-backend\venv\lib\site-packages\django\core\management\commands\migrate.py", line 234, in handle fake_initial=fake_initial, File "C:\Users\Pouya\Desktop\programs\python\marketpine-backend\venv\lib\site-packages\django\db\migrations\executor.py", line 117, in migrate state = self._migrate_all_forwards(state, plan, full_plan, fake=fake, fake_initial=fake_initial) File "C:\Users\Pouya\Desktop\programs\python\marketpine-backend\venv\lib\site-packages\django\db\migrations\executor.py", line 147, in _migrate_all_forwards state = self.apply_migration(state, migration, fake=fake, fake_initial=fake_initial) File "C:\Users\Pouya\Desktop\programs\python\marketpine-backend\venv\lib\site-packages\django\db\migrations\executor.py", line 245, in apply_migration state = migration.apply(state, schema_editor) File "C:\Users\Pouya\Desktop\programs\python\marketpine-backend\venv\lib\site-packages\django\db\migrations\migration.py", line 124, in apply operation.database_forwards(self.app_label, schema_editor, old_state, project_state) File "C:\Users\Pouya\Desktop\programs\python\marketpine-backend\venv\lib\site-packages\django\db\migrations\operations\fields.py", line 249, in database_forwards schema_editor.alter_field(from_model, from_field, to_field) File "C:\Users\Pouya\Desktop\programs\python\marketpine-backend\venv\lib\site-packages\django\db\backends\base\schema.py", line 535, in alter_field old_db_params, new_db_params, strict) File "C:\Users\Pouya\Desktop\programs\python\marketpine-backend\venv\lib\site-packages\django\db\backends\postgresql\schema.py", line 122, in _alter_field new_db_params, strict, File "C:\Users\Pouya\Desktop\programs\python\marketpine-backend\venv\lib\site-packages\django\db\backends\base\schema.py", line 648, in _alter_field old_default = self.effective_default(old_field) File "C:\Users\Pouya\Desktop\programs\python\marketpine-backend\venv\lib\site-packages\django\db\backends\base\schema.py", line 233, in effective_default return field.get_db_prep_save(self._effective_default(field), self.connection) File "C:\Users\Pouya\Desktop\programs\python\marketpine-backend\venv\lib\site-packages\django\db\backends\base\schema.py", line 212, in _effective_default default = field.get_default() …