2

According to the Django documentation (here):

django.contrib.sites registers a post_migrate signal handler which creates a default site named example.com with the domain example.com. This site will also be created after Django creates the test database. To set the correct name and domain for your project, you can use a data migration.

Isn't it safe to directly change the default values from the Django admin panel? why?

mahyard
  • 1,230
  • 1
  • 13
  • 34
  • I just change the default site object to the correct information when setting up a site. – markwalker_ Jan 15 '21 at 09:40
  • thank you @markwalker_, our website has worked for years and I'm not sure whether it's safe to just change those values or not. there are many relations in our database too. – mahyard Jan 15 '21 at 09:45
  • actually, my knowledge doesn't have any doubt here, but the official document made me confused. – mahyard Jan 15 '21 at 09:48
  • 1
    You'll be fine to just edit the default site. It gets used by various things internally. Things like the "view on site" button which you may have seen. – markwalker_ Jan 15 '21 at 09:57

2 Answers2

3

Here is my answer. First option is to change them on Django Admin site. Second option is to create a migration file manually and run your migrations. Let me describe the second option here. Firstly, create an empty migration using following command.

$ python manage.py makemigrations --empty --name update_site_name app_name

Next, refer to this blog to edit the migration file.

Finally, run your migrations.

Thank you.

Venus713
  • 1,441
  • 12
  • 24
0

Finally, I changed the site_name directly in my database. I realized that a site can have a migration to define a default site_name from scratch, but for a case like mine in which there are a lot of data it's not necessary to add a migration. In other words, you should add a migration when you are developing your site, not when it's on the production stage.

Thanks to @markwalker for his comment

mahyard
  • 1,230
  • 1
  • 13
  • 34