How to update Django model max_length value in database after tables have already been migrated












0















I need more characters available for the title and subtitle fields of a blog I made. I would like to increase the max_length from 100 to 150. Here is the table:



class Post(models.Model):
title = models.CharField(max_length=100)
subtitle = models.CharField(max_length=100)
slug = models.SlugField(max_length=99)
date_added = models.DateTimeField(default=timezone.now)
author = models.CharField(max_length=60)
body = models.TextField()
category = models.ForeignKey(Category, on_delete=models.CASCADE)
tags = models.ManyToManyField(Tag)


Through another Q&A I took the advice to change the max_length in the model (in my case from 100 to 150) and type this in the command prompt:



python manage.py makemigrations
python manage.py migrate


I then committed the changes and it allowed me to type more characters in but when I submitted the post it came up with a database error saying the fields can only take 100 characters.



How can I get the database to recognize the change in max_characters?










share|improve this question

























  • can you post file auto create by command makemigrations with lengh 100 and lengh 150?

    – Ngoc Pham
    Nov 26 '18 at 2:53
















0















I need more characters available for the title and subtitle fields of a blog I made. I would like to increase the max_length from 100 to 150. Here is the table:



class Post(models.Model):
title = models.CharField(max_length=100)
subtitle = models.CharField(max_length=100)
slug = models.SlugField(max_length=99)
date_added = models.DateTimeField(default=timezone.now)
author = models.CharField(max_length=60)
body = models.TextField()
category = models.ForeignKey(Category, on_delete=models.CASCADE)
tags = models.ManyToManyField(Tag)


Through another Q&A I took the advice to change the max_length in the model (in my case from 100 to 150) and type this in the command prompt:



python manage.py makemigrations
python manage.py migrate


I then committed the changes and it allowed me to type more characters in but when I submitted the post it came up with a database error saying the fields can only take 100 characters.



How can I get the database to recognize the change in max_characters?










share|improve this question

























  • can you post file auto create by command makemigrations with lengh 100 and lengh 150?

    – Ngoc Pham
    Nov 26 '18 at 2:53














0












0








0








I need more characters available for the title and subtitle fields of a blog I made. I would like to increase the max_length from 100 to 150. Here is the table:



class Post(models.Model):
title = models.CharField(max_length=100)
subtitle = models.CharField(max_length=100)
slug = models.SlugField(max_length=99)
date_added = models.DateTimeField(default=timezone.now)
author = models.CharField(max_length=60)
body = models.TextField()
category = models.ForeignKey(Category, on_delete=models.CASCADE)
tags = models.ManyToManyField(Tag)


Through another Q&A I took the advice to change the max_length in the model (in my case from 100 to 150) and type this in the command prompt:



python manage.py makemigrations
python manage.py migrate


I then committed the changes and it allowed me to type more characters in but when I submitted the post it came up with a database error saying the fields can only take 100 characters.



How can I get the database to recognize the change in max_characters?










share|improve this question
















I need more characters available for the title and subtitle fields of a blog I made. I would like to increase the max_length from 100 to 150. Here is the table:



class Post(models.Model):
title = models.CharField(max_length=100)
subtitle = models.CharField(max_length=100)
slug = models.SlugField(max_length=99)
date_added = models.DateTimeField(default=timezone.now)
author = models.CharField(max_length=60)
body = models.TextField()
category = models.ForeignKey(Category, on_delete=models.CASCADE)
tags = models.ManyToManyField(Tag)


Through another Q&A I took the advice to change the max_length in the model (in my case from 100 to 150) and type this in the command prompt:



python manage.py makemigrations
python manage.py migrate


I then committed the changes and it allowed me to type more characters in but when I submitted the post it came up with a database error saying the fields can only take 100 characters.



How can I get the database to recognize the change in max_characters?







python django django-models






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 26 '18 at 2:42







hckrieger

















asked Nov 26 '18 at 2:37









hckriegerhckrieger

213




213













  • can you post file auto create by command makemigrations with lengh 100 and lengh 150?

    – Ngoc Pham
    Nov 26 '18 at 2:53



















  • can you post file auto create by command makemigrations with lengh 100 and lengh 150?

    – Ngoc Pham
    Nov 26 '18 at 2:53

















can you post file auto create by command makemigrations with lengh 100 and lengh 150?

– Ngoc Pham
Nov 26 '18 at 2:53





can you post file auto create by command makemigrations with lengh 100 and lengh 150?

– Ngoc Pham
Nov 26 '18 at 2:53












1 Answer
1






active

oldest

votes


















0














You can change it and re run the migrations again or do python manage.py migrate my_app 0008_previous_migration you can then delete the newer migration file with the error in it and re run the commands.
You can do python manage.py showmigrations my_app






share|improve this answer
























  • Will deleting the migrations file and re-migrating the changes mess up the data in the database?

    – hckrieger
    Dec 12 '18 at 2:25











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53474090%2fhow-to-update-django-model-max-length-value-in-database-after-tables-have-alread%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














You can change it and re run the migrations again or do python manage.py migrate my_app 0008_previous_migration you can then delete the newer migration file with the error in it and re run the commands.
You can do python manage.py showmigrations my_app






share|improve this answer
























  • Will deleting the migrations file and re-migrating the changes mess up the data in the database?

    – hckrieger
    Dec 12 '18 at 2:25
















0














You can change it and re run the migrations again or do python manage.py migrate my_app 0008_previous_migration you can then delete the newer migration file with the error in it and re run the commands.
You can do python manage.py showmigrations my_app






share|improve this answer
























  • Will deleting the migrations file and re-migrating the changes mess up the data in the database?

    – hckrieger
    Dec 12 '18 at 2:25














0












0








0







You can change it and re run the migrations again or do python manage.py migrate my_app 0008_previous_migration you can then delete the newer migration file with the error in it and re run the commands.
You can do python manage.py showmigrations my_app






share|improve this answer













You can change it and re run the migrations again or do python manage.py migrate my_app 0008_previous_migration you can then delete the newer migration file with the error in it and re run the commands.
You can do python manage.py showmigrations my_app







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 26 '18 at 3:24









TaylorTaylor

589316




589316













  • Will deleting the migrations file and re-migrating the changes mess up the data in the database?

    – hckrieger
    Dec 12 '18 at 2:25



















  • Will deleting the migrations file and re-migrating the changes mess up the data in the database?

    – hckrieger
    Dec 12 '18 at 2:25

















Will deleting the migrations file and re-migrating the changes mess up the data in the database?

– hckrieger
Dec 12 '18 at 2:25





Will deleting the migrations file and re-migrating the changes mess up the data in the database?

– hckrieger
Dec 12 '18 at 2:25




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53474090%2fhow-to-update-django-model-max-length-value-in-database-after-tables-have-alread%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

404 Error Contact Form 7 ajax form submitting

How to know if a Active Directory user can login interactively

TypeError: fit_transform() missing 1 required positional argument: 'X'