django 1.10.3 Cannot resolve bases after flush - python

I have a playground for model developement.
When running python manage.py makemigrations the Error
Traceback (most recent call last):
File "manage.py", line 22, in <module>
execute_from_command_line(sys.argv)
File "/home/IPP-HGW/dboe/anaconda2/lib/python2.7/site-packages/django/core/management/__init__.py", line 367, in execute_from_command_line
utility.execute()
File "/home/IPP-HGW/dboe/anaconda2/lib/python2.7/site-packages/django/core/management/__init__.py", line 359, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/IPP-HGW/dboe/anaconda2/lib/python2.7/site-packages/django/core/management/base.py", line 294, in run_from_argv
self.execute(*args, **cmd_options)
File "/home/IPP-HGW/dboe/anaconda2/lib/python2.7/site-packages/django/core/management/base.py", line 345, in execute
output = self.handle(*args, **options)
File "/home/IPP-HGW/dboe/anaconda2/lib/python2.7/site-packages/django/core/management/commands/makemigrations.py", line 173, in handle
migration_name=self.migration_name,
File "/home/IPP-HGW/dboe/anaconda2/lib/python2.7/site-packages/django/db/migrations/autodetector.py", line 47, in changes
changes = self._detect_changes(convert_apps, graph)
File "/home/IPP-HGW/dboe/anaconda2/lib/python2.7/site-packages/django/db/migrations/autodetector.py", line 132, in _detect_changes
self.old_apps = self.from_state.concrete_apps
File "/home/IPP-HGW/dboe/anaconda2/lib/python2.7/site-packages/django/db/migrations/state.py", line 180, in concrete_apps
self.apps = StateApps(self.real_apps, self.models, ignore_swappable=True)
File "/home/IPP-HGW/dboe/anaconda2/lib/python2.7/site-packages/django/db/migrations/state.py", line 242, in __init__
self.render_multiple(list(models.values()) + self.real_models)
File "/home/IPP-HGW/dboe/anaconda2/lib/python2.7/site-packages/django/db/migrations/state.py", line 285, in render_multiple
"for more" % (new_unrendered_models, get_docs_version())
django.db.migrations.exceptions.InvalidBasesError: Cannot resolve bases for [<ModelState: 'main.Component'>, <ModelState: 'main.MagneticConfig'>, <ModelState: 'main.NetStructure'>, <ModelState: 'main.Program'>, <ModelState: 'main.FilePath'>]
This can happen if you are inheriting models from an app with migrations (e.g. contrib.auth)
in an app with no migrations; see https://docs.djangoproject.com/en/1.10/topics/migrations/#dependencies for more
Keeps occuring though i tried a hell of a lot:
of course python manage.py makemigration <appName>
python manage.py migrate <appName>
drop all tables from the app
python manage.py squashmigrations main 0001
emptied the models.py file
uncommented the app in settings
read everything i could find on that
flushing the whole database python manage.py flush
Any idea, how to solve this? Thanks,
Daniel
Edit Nov_29:
Stack trace added

Finally i got the solution. I found out, that the migrations are stored in a file in the application folder. You can delete these by hand. Of course, you need to be very careful with this.
Take a look at this if you got the same problem.

Related

Fix Conflicting migrations detected in Django1.9

I updated django-dynamic-model repository to support Django 1.9. I got this error:
CommandError:
Conflicting migrations detected; multiple leaf nodes in the migration
graph: (0001_initial, 0002_auto__add_field_dynamicschemafield_extra in
dynamicmodel).
To fix them run 'python manage.py makemigrations --merge'
After running python manage.py makemigrations --merge, I got another error:
File "/local/lib/python2.7/sitepackages/django/core/management/__init__.py",
line 353, in execute_from_command_line
utility.execute()
File "/local/lib/python2.7/sitepackages/django/core/management/__init__.py", line 345, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File
"/local/lib/python2.7/site-packages/django/core/management/base.py", line 348, in run_from_argv
self.execute(*args, **cmd_options)
File
"/local/lib/python2.7/site-packages/django/core/management/base.py", line 399, in execute
output = self.handle(*args, **options)
File
"/local/lib/python2.7/site-packages/django/core/management/commands/makemigrations.py", line 97, in handle
return self.handle_merge(loader, conflicts)
File
"/local/lib/python2.7/site-packages/django/core/management/commands/makemigrations.py", line 216, in handle_merge
raise ValueError("Could not find common ancestor of %s" % migration_names)
ValueError: Could not find common ancestor of set([u'0001_initial', u'0002_auto__add_field_dynamicschemafield_extra']).
Help me to find the solution.
The migrations need to have "straight" dependency chain, i.e. migration 0003 needs to depend on migration 0002, and 0002 on 0001.
You need to define this in the 0003_third.py like this:
class Migration(migrations.Migration):
dependencies = [
('modulename', '0002_second'),
]
Seems like you have injected models of other applications.
Define TARGET_APP in your migrations, seems like migrations loader can't correctly identify target app.

Django - A model can't have more than one AutoField

This problem randomly started appearing for me. I know that Django generates its own ids but a lot my code has been using custom AutoFields which HAS been working. I added a new class today and tried to makemigrations but this error keeps showing up.
I DID remove all instances of AutoFields and retried migrating but the problem still persists which leads me to believe it's something else... I don't believe my Django version has changed at all...
Error:
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "C:\Python34\lib\site-packages\django\core\management\__init__.py", line
338, in execute_from_command_line
utility.execute()
File "C:\Python34\lib\site-packages\django\core\management\__init__.py", line
330, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Python34\lib\site-packages\django\core\management\base.py", line 390,
in run_from_argv
self.execute(*args, **cmd_options)
File "C:\Python34\lib\site-packages\django\core\management\base.py", line 441,
in execute
output = self.handle(*args, **options)
File "C:\Python34\lib\site-packages\django\core\management\commands\makemigrat
ions.py", line 98, in handle
loader.project_state(),
File "C:\Python34\lib\site-packages\django\db\migrations\loader.py", line 326,
in project_state
return self.graph.make_state(nodes=nodes, at_end=at_end, real_apps=list(self
.unmigrated_apps))
File "C:\Python34\lib\site-packages\django\db\migrations\graph.py", line 231,
in make_state
project_state = self.nodes[node].mutate_state(project_state, preserve=False)
File "C:\Python34\lib\site-packages\django\db\migrations\migration.py", line 8
3, in mutate_state
operation.state_forwards(self.app_label, new_state)
File "C:\Python34\lib\site-packages\django\db\migrations\operations\fields.py"
, line 51, in state_forwards
state.reload_model(app_label, self.model_name_lower)
File "C:\Python34\lib\site-packages\django\db\migrations\state.py", line 152,
in reload_model
self.apps.render_multiple(states_to_be_rendered)
File "C:\Python34\lib\site-packages\django\db\migrations\state.py", line 262,
in render_multiple
model.render(self)
File "C:\Python34\lib\site-packages\django\db\migrations\state.py", line 546,
in render
body,
File "C:\Python34\lib\site-packages\django\db\models\base.py", line 189, in __
new__
new_class.add_to_class(obj_name, obj)
File "C:\Python34\lib\site-packages\django\db\models\base.py", line 324, in ad
d_to_class
value.contribute_to_class(cls, name)
File "C:\Python34\lib\site-packages\django\db\models\fields\__init__.py", line
989, in contribute_to_class
"A model can't have more than one AutoField."
AssertionError: A model can't have more than one AutoField.
Here's an example of one of my fields:
assetid = models.AutoField(primary_key=True)
A lot of my code already depends on the name itself so changing it is going to be a big issue. Furthermore, this was working perfectly before! I just can't seem to migrate it now. I should mention im using a sqlite3 db.
This is Because Django By default uses AutoField for the id.....so, if you want other fields to be AutoField, then make sure you confirm primary_key=True.
Doing so deletes the id field from the Database.
I have used Mysql as my database. Be sure this problem might not solve in other databases.
Deleted migration files and most recent history and fixed it.
I was having the same problem,
I commented out all the references to that model in all my app files, then run makemigrations and migrate, butit keeps telling that "A model can't have more than one AutoField." even if i am trying to deleting that file.
I had to reset my database.
in my case I deleted id Autofield ,it works fine for me as Django uses Autofield by default
better way is just unapply migrations(meaning run a previous migration).in this way the fields which sometimes are not removed from database are automatically removed from database.Then, after changes you can easily do makemigrations again and then migrate and everything will be good.

Setting Up Apache Solr on Local Instance of readthedocs.org

Link to Instructions
I am following the instructions at http://read-the-docs.readthedocs.org/en/latest/install.html#solr-search-setup
Question
Currently, I am able to set up a local instance of readthedocs.org; however, I cannot set up search correctly on it as I can't seem to generate the necessary schema.xml file by running the following command. The context of which is in the link above.
./manage.py build_solr_schema > $SOLR_PATH/solr/conf/schema.xml
Instead of successfully generating a schema.xml, I am presented with this error.
Traceback (most recent call last):
File "./manage.py", line 11, in <module>
execute_from_command_line(sys.argv)
File "/home/***/ford-env/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 399, in execute_from_command_line
utility.execute()
File "/home/***/ford-env/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 392, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/***/ford-env/local/lib/python2.7/site-packages/django/core/management/base.py", line 242, in run_from_argv
self.execute(*args, **options.__dict__)
File "/home/***/ford-env/local/lib/python2.7/site-packages/django/core/management/base.py", line 285, in execute
output = self.handle(*args, **options)
File "/home/***/ford-env/local/lib/python2.7/site-packages/haystack/management/commands/build_solr_schema.py", line 26, in handle
schema_xml = self.build_template(using=using)
File "/home/***/ford-env/local/lib/python2.7/site-packages/haystack/management/commands/build_solr_schema.py", line 52, in build_template
c = self.build_context(using=using)
File "/home/***/ford-env/local/lib/python2.7/site-packages/haystack/management/commands/build_solr_schema.py", line 38, in build_context
raise ImproperlyConfigured("'%s' isn't configured as a SolrEngine)." % backend.connection_alias)
I'm guessing there is an extra step involving for configuring solr with django before generating xml. Similar errors suggest editing a settings.py file, but I cannot seem to find one within the project directory. Due to my lack of familiarity with django, I don't know how to continue from here.
you have to update the settings files in readthedocs.org/readthedocs/settings/*.py and update the HAYSTACK_CONNECTIONS dict with (if you're using solr):
HAYSTACK_CONNECTIONS = {
'default': {
'ENGINE': 'haystack.backends.solr_backend.SolrEngine',
'URL': 'http://127.0.0.1:8983/solr',
}
}
check init.py, base.py, sqlite.py. Then it worked perfectly.

South migration fails

I have a problem with south migrations. I still don't understand how this did happen, and what should what path to move to resolve this
Romans-MacBook-Pro:holms$ ./manage.py migrate
cRunning migrations for accounts:
- Nothing to migrate.
- Loading initial data for accounts.
No fixtures found.
Running migrations for allocations:
- Nothing to migrate.
- Loading initial data for allocations.
No fixtures found.
Running migrations for adyen:
- Nothing to migrate.
- Loading initial data for adyen.
No fixtures found.
Running migrations for blog:
- Nothing to migrate.
- Loading initial data for blog.
No fixtures found.
Running migrations for offers:
- Nothing to migrate.
- Loading initial data for offers.
No fixtures found.
Running migrations for orders:
- Migrating forwards to 0011_update_price_fields.
> orders:0002_update_order_contact_information
Traceback (most recent call last):
File "./manage.py", line 15, in <module>
execute_manager(settings)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/__init__.py", line 438, in execute_manager
utility.execute()
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/__init__.py", line 379, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/base.py", line 191, in run_from_argv
self.execute(*args, **options.__dict__)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/base.py", line 220, in execute
output = self.handle(*args, **options)
File "/Users/holms/Development/xxx/xxx/settings/../../lib/south/management/commands/migrate.py", line 105, in handle
ignore_ghosts = ignore_ghosts,
File "/Users/holms/Development/xxx/xxx/settings/../../lib/south/migration/__init__.py", line 191, in migrate_app
success = migrator.migrate_many(target, workplan, database)
File "/Users/holms/Development/xxx/xxx/settings/../../lib/south/migration/migrators.py", line 221, in migrate_many
result = migrator.__class__.migrate_many(migrator, target, migrations, database)
File "/Users/holms/Development/xxx/xxx/settings/../../lib/south/migration/migrators.py", line 292, in migrate_many
result = self.migrate(migration, database)
File "/Users/holms/Development/xxx/xxx/settings/../../lib/south/migration/migrators.py", line 125, in migrate
result = self.run(migration)
File "/Users/holms/Development/xxx/xxx/settings/../../lib/south/migration/migrators.py", line 99, in run
return self.run_migration(migration)
File "/Users/holms/Development/xxx/xxx/settings/../../lib/south/migration/migrators.py", line 81, in run_migration
migration_function()
File "/Users/holms/Development/xxx/xxx/settings/../../lib/south/migration/migrators.py", line 57, in <lambda>
return (lambda: direction(orm))
File "/Users/holms/Development/xxx/migrations/0002_update_order_contact_information.py", line 29, in forwards
for o in orders:
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/db/models/query.py", line 107, in _result_iter
self._fill_cache()
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/db/models/query.py", line 772, in _fill_cache
self._result_cache.append(self._iter.next())
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/db/models/query.py", line 273, in iterator
for row in compiler.results_iter():
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 680, in results_iter
for rows in self.execute_sql(MULTI):
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 735, in execute_sql
cursor.execute(sql, params)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/db/backends/util.py", line 34, in execute
return self.cursor.execute(sql, params)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/db/backends/sqlite3/base.py", line 234, in execute
return Database.Cursor.execute(self, query, params)
django.db.utils.DatabaseError: no such column: orders_order.pre_paid
part of migration file [0002_update_order_contact_information.py] which breaks:
# encoding: utf-8
import datetime
from south.db import db
from south.v2 import DataMigration
from django.db import models
class Migration(DataMigration):
def forwards(self, orm):
Order = models.get_model('orders', 'Order')
orders = Order.all_objects.select_related('buyer')
orders = orders.filter(first_name__isnull=True)
orders = orders.filter(buyer__isnull=False)
orders = orders.exclude(payment_status="UNFINISHED")
userfields = (
'gender', 'birth_date', 'first_name', 'last_name', 'street_number',
You should not interact with your models directly like that. You use django.models, but that version of the models are in a wrong state. You want the state of the models as they were in migration 0002. The south manual states that you should access your models through the orm parameter.
Notice that we use orm.User to access the User model - this gives us the version of User from when this migration was created, so if we want to run the migration in future, it won’t get a completely different, new, User model. source
So you should rewrite the migration like this:
orders = orm.Order.objects.all()
Or even like this:
Order = orm.Order

Any idea why i am getting this error?

I am trying to install django-cms in my ubuntu pc. I am getting this error:
Traceback (most recent call last):
File "manage.py", line 14, in <module>
execute_manager(settings)
File "/usr/local/lib/python2.6/dist-packages/django/core/management/__init__.py", line 438, in execute_manager
utility.execute()
File "/usr/local/lib/python2.6/dist-packages/django/core/management/__init__.py", line 379, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/local/lib/python2.6/dist-packages/django/core/management/base.py", line 191, in run_from_argv
self.execute(*args, **options.__dict__)
File "/usr/local/lib/python2.6/dist-packages/django/core/management/base.py", line 209, in execute
translation.activate('en-us')
File "/usr/local/lib/python2.6/dist-packages/django/utils/translation/__init__.py", line 100, in activate
return _trans.activate(language)
File "/usr/local/lib/python2.6/dist-packages/django/utils/translation/trans_real.py", line 202, in activate
_active.value = translation(language)
File "/usr/local/lib/python2.6/dist-packages/django/utils/translation/trans_real.py", line 185, in translation
default_translation = _fetch(settings.LANGUAGE_CODE)
File "/usr/local/lib/python2.6/dist-packages/django/utils/translation/trans_real.py", line 162, in _fetch
app = import_module(appname)
File "/usr/local/lib/python2.6/dist-packages/django/utils/importlib.py", line 35, in import_module
__import__(name)
File "/usr/local/lib/python2.6/dist-packages/cms/__init__.py", line 14, in <module>
patch_settings()
File "/usr/local/lib/python2.6/dist-packages/cms/conf/__init__.py", line 32, in patch_settings
post_patch()
File "/usr/local/lib/python2.6/dist-packages/cms/conf/patch.py", line 26, in post_patch
settings.CMS_TEMPLATES = tuple(settings.CMS_TEMPLATES) + (
TypeError: 'NoneType' object is not iterable
Any idea why is this error coming?
thanks
Edit -1 --
HI guys,
Yes you were rightm i didnt put cms_templates in settings.py. I did it now, but now I am getting this error.
DatabaseError at /
no such table: cms_page
Request Method: GET
Request URL: http://localhost:8000/
Django Version: 1.3
Exception Type: DatabaseError
Exception Value:
no such table: cms_page
Exception Location: /usr/local/lib/python2.6/dist-packages/django/db/backends/sqlite3/base.py in execute, line 234
Python Executable: /usr/bin/python
Python Version: 2.6.6
Python Path:
['/home/naveen/django_projects/myproject',
'/usr/local/lib/python2.6/dist-packages/pip-0.8.3-py2.6.egg',
'/usr/lib/python2.6',
'/usr/lib/python2.6/plat-linux2',
'/usr/lib/python2.6/lib-tk',
'/usr/lib/python2.6/lib-old',
'/usr/lib/python2.6/lib-dynload',
'/usr/local/lib/python2.6/dist-packages',
'/usr/lib/python2.6/dist-packages',
'/usr/lib/python2.6/dist-packages/PIL',
'/usr/lib/python2.6/dist-packages/gst-0.10',
'/usr/lib/pymodules/python2.6',
'/usr/lib/python2.6/dist-packages/gtk-2.0',
'/usr/lib/pymodules/python2.6/gtk-2.0']
Server time: Fri, 25 Mar 2011 15:34:04 -0500
It's looking for a settings.CMS_TEMPLATES. It's trying to make None a tuple which would throw that error.
Make sure you have a CMS_TEMPLATES defined.
http://docs.django-cms.org/en/2.1.3/getting_started/tutorial.html#configuration-and-setup
Your CMS_TEMPLATES settings is None, I have no idea what that is, but I'm guessing it a setting you need to configure somewhere.
settings.CMS_TEMPLATES is None, I believe. It's hard to tell without a sample of the code in question.
Referring to edit 1:
Which commands are you using? Are you following the tutorial? I guess you did not do:
python manage.py syncdb
If you just wrote your models, this command will create the tables in the db. Otherwise the database is empty, which is the reason why Django can't find the cms_pagetable.

Categories