Hi,

You are changing a CharField into a ForeignKey field with data present. So
when the migration tries to run, the reports_to field contains information
with a string in it - the database server then tries to set it to a
ForeignKey field, which is an integer field per default. This data
migration doesn't work and that is what the error is saying.

This can't be migrated automatically without writing your own migrations
and even then it won't be easy,.

If you don't care about the current value of the reports_to field, you can
do this in 2 migrations - one to remove the field and another to add the
foreign key field. Or you can just add a drop column for the old reports to
field in the same migration.

If you do care, I would probably do something like this:
1. Rename the current field.
2. Add the new foreign key field
3. Migrate the data via a custom migration.

Regards,

Andréas


Den mån 12 nov. 2018 kl 17:39 skrev china <challakart...@gmail.com>:

> Hi Experts,
>
> I am trying to change the charfield to ForeignKey and I am running my code
> I am getting the following error if do python manage.py migrate
>
> django.db.utils.DataError: invalid input syntax for integer: "Jeff"
>
>
> Here is my code
>
>
> BEFORE
>
> ------
>
>
> reports_to = models.CharField(max_length=128, blank=True, null=True)
>
>
> in_country_manager = models.CharField(max_length=128, blank=True, null=
> True)
>
> After
> ------
>
> reports_to = models.ForeignKey("self", null=True, blank=True, related_name
> ="employee_reports_to")
>
>
> Could any please help with this issue.
>
>
> Thanks,
>
> Karthik
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/20ca05ad-6486-489c-91fc-62adf615dee3%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/20ca05ad-6486-489c-91fc-62adf615dee3%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAK4qSCcpCfsWvuTn0OZWD8tGY5_bhfeUVMr-SkJEB1nwfpWLFQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to