Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3390676
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T03:43:08+00:00 2026-05-18T03:43:08+00:00

Creating my tables from my models.py . I donno how to do 2 things

  • 0

Creating my tables from my models.py. I donno how to do 2 things –

  1. I want to specify MySQL to create some of my tables as InnoDB & some as MyISAM. How do I do it?
  2. Also I want to specify my tables DEFAULT CHARSET as utf8. How do I do it?

This is what I see when I run syncdb –

...
) ENGINE=MyISAM DEFAULT CHARSET=latin1

I use Ubuntu 10.04, Django 1.2.X, MySQL 5.1.X

UPDATE:
I thought these might be MySQL default settings & I ended up changing my.cnf where I added default-character-set = utf8. But to no use.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T03:43:09+00:00Added an answer on May 18, 2026 at 3:43 am

    I don’t think you can change storage engines on a table-by-table basis, but you can do it on a database-by-database basis. This, of course, means that InnoDB foreign key constraints, for example, can’t apply to foreign keys to MyISAM tables.

    So you need to declare two “databases”, which may very well be on the same server:

    DATABASES = {
        'default': {
            'ENGINE': 'django.db.backends.mysql',
            #...
        }
        'innodb': {
            'ENGINE': 'django.db.backends.mysql',
            #...
            'OPTIONS': { 'init_command': 'SET storage_engine=INNODB;' }
        }
    }
    

    And you’ll just need to apply using('innodb') to querysets for tables in InnoDB land.

    As for UTF-8, again, I think you need to do this at the database level. I don’t think syncdb creates the database for you, just the tables. You should create the database manually anyway, so you can have privileges set right before running syncdb. The database creation command you want is:

    CREATE DATABASE django CHARACTER SET utf8;
    

    That said, I usually recommend that people create two django users in the database: one for database schema work (“admin”) and one for everything else (with different passwords):

    CREATE DATABASE django CHARACTER SET utf8;
    CREATE USER 'django_site'@'localhost' IDENTIFIED BY 'password';
    GRANT SELECT, INSERT, UPDATE, DELETE ON django.* TO django_site;
    CREATE USER 'django_admin'@'localhost' IDENTIFIED BY 'password';
    GRANT SELECT, INSERT, UPDATE, DELETE ON django.* TO django_admin;
    GRANT CREATE, DROP, ALTER, INDEX, LOCK TABLES ON django.* TO django_admin;
    FLUSH PRIVILEGES;
    

    (Note that this needs to be done for each database.)

    For this to work, you need to modify manage.py:

    import sys
    if len(sys.argv) >= 2 and sys.argv[1] in ["syncdb", "dbshell", "migrate"]:
        os.environ['DJANGO_ACCESS'] = "ADMIN"
    

    Then in your settings.py, use the environment variable to pick the right settings. Make sure the site (i.e. non-admin) user is the default.

    (Additionally, I don’t store the database setup, SECRET_KEY, or anything else sensitive in settings.py because my Django project is stored in Mercurial; I have settings.py pull all that in from an external file accessible only by Django’s user and the server admins. I’ll leave the “how” as an exercise for the reader… because I detailed some of it in answers to others’ questions, and I’m too lazy to look it up right now.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When creating reports using BIRT 2.3.1, I don't want page breaks inside tables or
I'm creating a user-based website. For each user, I'll need a few MySQL tables
I'm attempting at creating a menu from a table using the Suckerfish css menu
Does anyone have any suggestions for creating meta tables in a database? These tables
Usually when I'm creating indexes on tables, I generally guess what the Fill Factor
Visual Studio 2005 doesn't provide an interface for creating relationships between tables in a
Initialization would include creating all the required tables, constraints and populating the tables. edit:
I am trying to creating an optional association between a couple of tables. I
I'm tasked with creating a datawarehouse for a client. The tables involved don't really
I have an SQL database with multiple tables, and I am working on creating

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.