Django 1.7 makemigrations renaming tables to None

2024/10/6 18:29:48

I had to move a few models from one app to another, and I followed the instructions on this answer https://stackoverflow.com/a/26472482/188614.
Basically I used the CreateModel migrations generated by python manage.py makemigrations, wrapped them inside state_operations, and added the 'db_table' meta option with the old table's name.
Everything works fine, the models on the new_app are corretly using the old tables.
But if I run python manage.py makemigrations new_app it creates an AlterModelTable migration for each table renaming them as None, like this:

migrations.AlterModelTable(name='cidade',table=None,
),

Is this a bug, or expected behaviour?

Answer

I just had this problem myself.

The answer you were following includes this in the migration in new_app:

options={'db_table': 'newapp_themodel',
},

This options dict should reflect the values set by the Meta class on your model. In my case, I was not setting db_table in Meta, but had blindly copied the options code.

You need to update the options in your migration for newapp to either remove the db_table value if you don't set it in Meta or to match the value you set in Meta.

https://en.xdnf.cn/q/70339.html

Related Q&A

TypeError on CORS for flask-restful

While trying the new CORS feature on flask-restful, I found out that the decorator can be only applied if the function returns a string. For example, modifying the Quickstart example:class HelloWorld(r…

struct.error: unpack requires a string argument of length 16

While processing a PDF file (2.pdf) with pdfminer (pdf2txt.py) I received the following error:pdf2txt.py 2.pdf Traceback (most recent call last):File "/usr/local/bin/pdf2txt.py", line 115, in…

SELECT EXISTS vs. LIMIT 1

I see SELECT EXISTS used a lot like:if db.query("""SELECT EXISTS (SELECT 1 FROM checkoutWHERE checkout_id = %s)""" % checkout_id).getresult()[0][0] == t:vs. what i prefer:…

How to access a specific start_url in a Scrapy CrawlSpider?

Im using Scrapy, in particular Scrapys CrawlSpider class to scrape web links which contain certain keywords. I have a pretty long start_urls list which gets its entries from a SQLite database which is …

Escaping search queries for Googles full text search service

This is a cross-post of https://groups.google.com/d/topic/google-appengine/97LY3Yfd_14/discussionIm working with the new full text search service in gae 1.6.6 and Im having trouble figuring out how to …

dificulty solving a code in O(logn)

I wrote a function that gets as an input a list of unique ints in order,(from small to big). Im supposed to find in the list an index that matches the value in the index. for example if L[2]==2 the out…

Scrapy. How to change spider settings after start crawling?

I cant change spider settings in parse method. But it is definitely must be a way. For example:class SomeSpider(BaseSpider):name = mySpiderallowed_domains = [example.com]start_urls = [http://example.co…

numpy ctypes dynamic module does not define init function error if not recompiled each time

sorry for yet an other question about dynamic module does not define init function. I did go through older questions but I didnt find one which adress my case specifically enought.I have a C++ library …

How do I save Excel Sheet as HTML in Python?

Im working with this library XlsxWriter.Ive opened a workbook and written some stuff in it (considering the official example) - import xlsxwriter# Create a workbook and add a worksheet. workbook = xlsx…

Faster sockets in Python

I have a client written in Python for a server, which functions through LAN. Some part of the algorithm uses socket reading intensively and it is executing about 3-6 times slower, than almost the same …