So I'm trying to add a SearchVectorField to a model in Django:
search_vector = SearchVectorField()
You are trying to add a non-`nullable` field 'search_vector' to jobposting without a default;
we can't do that (the database needs something to populate existing rows).
Please select a fix:
1) Provide a one-off default now
(will be set on all existing rows with a null value for this column)
2) Quit, and let me add a default in models.py
Select an option:
I am not entirely sure why you do not want to have a default value, but I will assume this as given.
My question is, is there any way to force makemigrations and migrate as I don't understand the problem if the table is empty.
Your current database table might be empty, but migrations are supposed to be repeatable on other database instances. Therefore Django cannot assume that the same holds on any other database.
A workaround might be to do define a migration that creates the field as nullable, indexes all entries and then updates it to be non-nullable.
# -*- coding: utf-8 -*- from __future__ import unicode_literals from django.contrib.postgres.search import SearchVector, SearchVectorField from django.db import migrations def index_entries(apps, schema_editor): Entry = apps.get_model("mymodel", "Entry") Entry.objects.update(search_vector=SearchVector('body_text')) class Migration(migrations.Migration): dependencies = [ ('mymodel', '0001_initial'), ] operations = [ migrations.AddField( model_name='entry', name='search_vector', field=SearchVectorField(null=True), ), migrations.RunPython(index_entries), migrations.AlterField( model_name='entry', name='search_vector', field=SearchVectorField(null=False), ), ]